Using lsqnonlin for deconvolution

4 views (last 30 days)
Jack
Jack on 24 Mar 2023
Moved: Matt J on 25 Mar 2023
The system I'm trying to solve is as follows:
Ip(t) is the output and ui(t) is the input. The purpose of the exercise is to determine the values of the ui with known values of Ip and k. I have experimental values of the input and the output, and want to create a script that penalizes the difference between consecutive input values and penalizes the difference between the estimated input and the actual input. I've attached the data, and what I've written so far is below. The problem I'm having is that the originally estimated value for the input never changes. It just stays zero.
filename='assignment_5_data.xlsx';
File=readtable(filename);
basal_insulin=File{:,2}/60;
plasma_insulin=File{:,3};
b=zeros(1,89);
A=lsqnonlin(@insulin,b);
function F=insulin(x)
filename='assignment_5_data.xlsx';
File=readtable(filename);
basal_insulin=File{:,2}/60;
plasma_insulin=File{:,3};
x=zeros(89,1);
k=0.0107;
qi2=(plasma_insulin-5.1873)/9.8834;
dqi2dt=[0];
for i=1:1:(length(qi2)-1)
dqi2dt(end+1)=(qi2(i+1)-qi2(i))/10;
end
qi1=(dqi2dt+k*qi2)/k;
dqi1dt=[0];
for j=1:1:(length(qi1)-1)
dqi1dt(end+1)=(qi1(j+1)-qi1(j))/10;
end
error=0;
for g=1:length(x)
error=error+(basal_insulin(g)-x(g))^2;
end
smooth=0;
for h=1:(length(x)-1)
smooth=smooth+abs(x(h+1)-x(h));
end
F=[error smooth];
plot(x)
end

Answers (1)

Torsten
Torsten on 24 Mar 2023
Moved: Matt J on 25 Mar 2023
lsqnonlin tries to adjust x, and you reset it to 0:
function F=insulin(x)
...
x=zeros(89,1);
This destroys the complete fitting procedure.
Further, lsqnonlin expects you to return a vector of length 89 the elements of which are the errors over the time intervals. You return only 2 single values.

Categories

Find more on Quadratic Programming and Cone Programming in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!