optimization with system of ode and data error # arguments
1 次查看(过去 30 天)
显示 更早的评论
I am trying to use fminsearch with my system of ODE with one ODE being optimized to the data. I am getting these errors:
Error using @(c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14)foo(c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,tdata,xdata) Not enough input arguments.
Error in fminsearch (line 190) fv(:,1) = funfcn(x,varargin{:});
Error in optimtest2b (line 19) psolve = fminsearch(@(c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14)foo(c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,tdata,xdata),x0);
And here's my code:
xdata = xlsread('50nm split.xlsx','B2:B1201');
tdata = xlsread('50nm split.xlsx','A2:A1201');
c1=.005; c2=100; c3=c1; c4=c2; c5=.1; c6=2.6;
c7=c5; c8=c5; c9=.5; c10=1.16; c11=.2; c12=0; c13=0; c14=2.2e10;
x0 =[20000;75;0;0;0;0;0;0;0;0;.05;0;.05;];
psolve = fminsearch(@(c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14)foo(c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,tdata,xdata),x0);
function:
function r = foo(c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,tdata, xdata, is_plotting,x0)
%x0 =[20000;75;0;0;0;0;0;0;0;0;.05;0;.05;];
[~, Y] = ode45(@myode, tdata, x0)
if is_plotting
plot(tdata, Y, 'b', tdata, xdata, 'rx');
end
r = sum(xdata - Y).^2;
function dx = myode(c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,t,x)
dx_dt(1)=-c1.*x(1).*x(3)+c2.*x(4)-c3.*x(1).*x(5)+c4.*x(6);
dx_dt(2)=-c5.*x(2).*x(3)+c6.*x(5)-c7.*x(2).*x(4)+c8.*x(6);
dx_dt(3)=x(10)-c1.*x(1).*x(3)+c2.*x(4)-c5.*x(2).*x(3)+c6.*x(5)+c9.*x(9).*x(8);
dx_dt(4)=c1.*x(1).*x(3)-c2.*x(4)-c7.*x(2).*x(4)+c8.*x(6);
dx_dt(5)=c5.*x(2).*x(3)-c6.*x(5)-c3.*x(1).*x(5)+c4.*x(6);
dx_dt(6)=c7.*x(2).*x(4)-c8.*x(6)+c3.*x(1).*x(5)-c4.*x(6)-c10.*x(6);
dx_dt(7)=c9.*x(9).*x(8);
dx_dt(8)=c10.*x(6).*(1-c11)-c9.*x(9).*x(8);
dx_dt(9)=c10.*x(6).*c11-c9.*x(9).*x(8);
dx_dt(10)=c12.*x(13).*x(11)-c13.*x(10);
dx_dt(11)=-c12.*x(13).*x(11)+c13.*x(10);
dx_dt(12)=c10.*x(6).*(1-c11).*c14-x(12);
dx_dt(13)=-c12.*x(13).*x(11)+c13.*x(10);
dx=Y(:,12);
end
end
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!