nonlinear data fitting for a system of ODE using lsqcurvefit (finding unknown parameters)
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
I have a set of experimental data in staedy state condtion(without time dependent). This experiment has been done at 4 different concentration including 3 compounds. the values of concentration at inlet(x=0) and outlet(x=1) are known. i used ODE15s to solve the differenial equations and find the values at outlet and then compare them with real values to find the unknown kinitic parameters(i followed https://www.mathworks.com/matlabcentral/answers/43439-monod-kinetics-and-curve-fitting#comment_89455). but when i ran the code i got some error as below: Not enough input arguments.
Error in Untitled10>objfun (line 25)
[tSol,YSol]=ode15s(@diffeq,x,Z);
Error in lsqcurvefit (line 202)
initVals.F = feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:});
Error in Untitled10 (line 20)
[kfit,Rsdnrm,Rsd,ExFlg,OptmInfo,Lmda,Jmat]=lsqcurvefit(@objfun,K,Cin,yy)
Caused by:
Failure in initial objective function evaluation. LSQCURVEFIT cannot continue.
댓글 수: 3
clc
clear all
global K
Y0=[0 0 0
293.3 2.141445291 3.688379481
462.8 2.536287882 4.200913729
966.2 2.352145581 6.525317012
1920 2.454642817 11.40142937
];
K=[1 2 1];
dt=0.001;
x=[0:dt:0.02]';
Cin=[0;200;500;1000;2000];
yy=[0 0 0
208.0886316 33.822843 78.56152111
376.5730526 31.98339108 168.7154254
802.9630526 29.05423171 204.8119954
1770 35.44630378 295.906807
];
[kfit,Rsdnrm,Rsd,ExFlg,OptmInfo,Lmda,Jmat]=lsqcurvefit(@objfun,K,Cin,yy)
function [C]=objfun(K,Y0,x)
for i=1:5
Z=Y0(i,:);
[tSol,YSol]=ode15s(@diffeq,x,Z);
C(i,:)=YSol(end,:)
end
end
function dYdt = diffeq(x,Y)
global K
k1=K(1);
k2=K(2);
k3=K(3);
dadt=-k1*Y(1)/(1+k1*Y(1));
dbdt=k1*Y(1)/(1+k1*Y(1))-k2*Y(2);
dcdt=k2*Y(2)-k3*Y(3);
dYdt=[dadt;dbdt;dcdt];
end
@Mojtaba Malayeri — Please post the image you included with your previous (now deleted) Question.
It is essential to understanding what you want to do.
@Star Strider that image was my experimental data, it is included in my code now.
채택된 답변
[kfit,Rsdnrm,Rsd,ExFlg,OptmInfo,Lmda,Jmat]=lsqcurvefit(@(K) objfun(K,Y0,x),K,Cin,yy)
댓글 수: 23
thank you for your response, but i got error again:
Error using Untitled10>@(K)objfun(K,x,Y0)
Too many input arguments.
Error in lsqcurvefit (line 202)
initVals.F = feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:});
Error in Untitled10 (line 20)
[kfit,Rsdnrm,Rsd,ExFlg,OptmInfo,Lmda,Jmat]=lsqcurvefit(@(K) objfun(K,x,Y0),K,Cin,yy)
Caused by:
Failure in initial objective function evaluation. LSQCURVEFIT cannot continue.
Your objective function doesn't seem to have any dependence on Cin. It should look like this
yy_predicted = objfun(K,Cin_data)
becaue this problem is steady-stat, i dont have data at different x between x=0:1 (i have only data of inlet and outlet). but it is done at different concentration; so Y0 is my inlet and yy is my outlet. each number in C_in related to a row of matrix Y0. I hope I have explained it well
Then, shouldn't you have this?
lsqcurvefit(@(a,b) objfun(a,b,x), K,Y0,yy)
sorry, what are a and b here? actually, Y0 should be replaced instead of Cin but it is a vector 5*3. i got erorr
They are the names of inputs to fun(a,b) where fun is the two-argument anonymous function created as follows,
fun = @(a,b) objfun(a,b,x) ;
i replaced this function in main file: [kfit,Rsdnrm,Rsd,ExFlg,OptmInfo,Lmda,Jmat]=lsqcurvefit(@(K,Y0) objfun(K,Y0,x), K,Y0,yy) but i got following message and can not be calculated: Optimization completed because the size of the gradient at the initial point is less than the default value of the optimality tolerance.
This runs for me without error messages:
Y0=[0 0 0
293.3 2.141445291 3.688379481
462.8 2.536287882 4.200913729
966.2 2.352145581 6.525317012
1920 2.454642817 11.40142937
];
K0=[1 2 1]; %<---Change
dt=0.001; %<---Change
x=[0:dt:0.02]';
%Cin=[0;200;500;1000;2000]; %<---Change
yy=[0 0 0
208.0886316 33.822843 78.56152111
376.5730526 31.98339108 168.7154254
802.9630526 29.05423171 204.8119954
1770 35.44630378 295.906807
];
[kfit,Rsdnrm,Rsd,ExFlg,OptmInfo,Lmda,Jmat]=...
lsqcurvefit(@(a,b) objfun(a,b,x),K0,Y0,yy) %<---Change
function [C]=objfun(K,Y0,x)
for i=1:5
Z=Y0(i,:);
[tSol,YSol]=ode15s(@(a,b)diffeq(a,b,K) ,x,Z); %<---Change
C(i,:)=YSol(end,:);
end
end
function dYdt = diffeq(x,Y,K)
%global K <---Change
k1=K(1);
k2=K(2);
k3=K(3);
dadt=-k1*Y(1)/(1+k1*Y(1));
dbdt=k1*Y(1)/(1+k1*Y(1))-k2*Y(2);
dcdt=k2*Y(2)-k3*Y(3);
dYdt=[dadt;dbdt;dcdt];
end
Yes, it works now. thank you so much. i really appriciate. just my fitting value are negative. how can i add possitive constrain for unknown fitting parameters??
You're welcome, but please Accept-click the answer if it solved your problem. To add positivity constraints:
lowerbounds=[0;0;0];
... = lsqcurvefit(@(a,b) objfun(a,b,x),K0,Y0,yy,lowerbounds);
i replace a lowerbound as follow, but i one of my parameter is negative: [kfit,Rsdnrm,Rsd,ExFlg,OptmInfo,Lmda,Jmat]=... lsqcurvefit(@(a,b) objfun(a,b,x),K0,Y0,yy,[0;0;0]) another issue is that Rsdnrm =7.1019e+04 that is very large error
You need to make lowerbounds a vector, like in my example.
yes, sorry i made mistake. but Rsdnrm = 2.1754e+05 is reasonable??
Who knows? If you re-run as below, it will solve the exact same optimization problem, but give you a much smaller Rsdnrm,
[kfit,Rsdnrm,Rsd,ExFlg,OptmInfo,Lmda,Jmat]=...
lsqcurvefit(@(a,b) objfun(a,b,x)/1e5,kfit,Y0,yy/1e5,[0;0;0])
because i have to use these parameters in another model to find the exact result. so it is very important to find the accurate values for these parameters.
How well is it working on simulated Y0,yy data (for which you know the true K)?
the error is very large. i even change the initial gusses for fitting parameters, but the erorr doesn't change.
i checked it, but there are big differenc between them: simulated=[0 0 0 293.2800001 0.000216393 5.849608311 462.78 0.000216393 6.756985175 966.18 0.000216393 8.897246179 1919.98 0.000216393 13.87585578]
real value=[0 0 0 208.0886316 33.822843 78.56152111 376.5730526 31.98339108 168.7154254 802.9630526 29.05423171 204.8119954 1770 35.44630378 295.906807]
i changed every parameters, but the erorr value is fixed at 2.17e+05. i don't know where this issue come from!!!!!!!!!
you mean i have to change my optimization solver instead of lsqcurvefit??
No. The link I gave you gives advice applicable to all solvers.
Thanks for the suggestion. i implimened all case of options, but the issue still persists. very large erorr.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Nonlinear Least Squares (Curve Fitting)에 대해 자세히 알아보기
참고 항목
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
