基于优化的线拟合

问题描述

我正在使用以下优化脚本,通过该脚本在两点 y_1(t_1=0)=1 和 y_2(t_2=10) 之间拟合以下曲线 y(t)=c_1+c_2 e^{-t} =7

我的问题是,如何通过添加约束 y(t=5)>4 来解决相同的优化问题?

clc;
clear;

tic

%The Data: Time and response data
t = [0 10]';
y = [1 7]';
%Look at the Data
subplot(2,1,1)
plot(t,y,'*','MarkerSize',10)
grid on
xlabel('Time')
ylabel('Response')
hold on
%Curve to Fit
E = [ones(size(t)) exp(-t)]
%Solving constrained linear least squares problem
% cNew = lsqlin(E,[],[1 1],y(1),opt) % Solver-based approach
p = optimproblem;
c = optimvar('c',2);
p.ObjectiveSense = 'minimize';
p.Objective = sum((E*c-y).^2);
% constraint example: p.Constraints.intercept = c(1) + c(2) == 0.82
sol = solve(p);
cNew = sol.c;
tf = (0:0.1:10)';
Ef = [ones(size(tf)) exp(-tf)];
yhatc = Ef*cNew;
%plot the curve\
subplot(2,2)
plot(t,10)
grid on
xlabel('Time')
ylabel('Response')
hold on
plot(tf,yhatc)
title('y(t)=c_1 + c_2e^{-t}')

toc

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)