k******o 发帖数: 61 | 1 【 以下文字转载自 Mathematics 讨论区 】
发信人: kafeimao (咖啡毛), 信区: Mathematics
标 题: 一个关于用matlab解微分方程的小问题
发信站: BBS 未名空间站 (Sun May 8 17:29:15 2011, 美东)
大家好,我要用matlab做变系数微分方程组的参数拟合,参考其他论坛上的教程,我修
改了自己的程序如下:
function dy=dydt(t,y,k)
dy=zeros(2,1)
dy(1)=0.0321*k(1)*(k(2)-y(1))-k(3)*y(1)-y(2)
dy(2)=0.25*k(4)*exp(-k(4)*t)*k(2);
function y=numcal(k,x)
global y0
tspan=[0 max(x)];
[m,n]=size(x);
[tt yy] = ode23s(@dydt,tspan,y0,[],k);
yc=spline(tt',yy',x);
y=yc;
主程序
clc;clear;
global y0
xdata=[1,2,3,4];ydata=data[3,4,5,6];
k0=[0,0,0,0,];%要识别参数的初始值
lb=[0,0,0,0];%要识别参数的下限
ub=[6.5,5,6];%要识别参数的上限;课根据参数的范围自己设定。
options=optimset('TolFun',1e-20,'TolX',1e-20,'MaxFunEvals',100,'Algorithm','
trust-region-reflective','Display','iter');
beta=lsqcurvefit(@numcal,k0,xdata,ydata,lb,ub,options);
Jc=numcal(k,xdata);
plot(xdata,ydata,'o',xdata,Jc);%画图查看参数识别后目标值和实验目标值之间的差
异;
结果还是出现错误:“??? Error using ==> odearguments at 19
When the first argument to ode23s is a function handle, the tspan and y0
arguments must be supplied.
Error in ==> ode23s at 188
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Error in ==> numcal at 8
[tt yy] = ode23s(@dydt,tspan,y0,[],k);
Error in ==> lsqcurvefit at 209
initVals.F = feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:});
Caused by:
Failure in initial user-supplied objective function evaluation.
LSQCURVEFIT cannot continue.”
请问我的错误在哪里,纠结了几天了,还是查不出来,谢谢大家。 |
|