八度的lsode函数

时间:2020-09-13 17:07:31

标签: octave equation dgl

我写了下面的代码,它工作了好几个星期没有任何问题。 突然,它停止工作并显示以下错误:

"warning: lsode: passing function body as a string is obsolete; please use anonymous functions
warning: called from
heun at line 23 column 2
error: 'f' undefined near line 1 column 42
error: lsode: evaluation of user-supplied function failed
error: called from
__lsode_fcn__C__ at line 1 column 40
heun at line 23 column 2"

代码是:

function yn=euler(t0,y0,tend,f,n)
t0=input('Gib hier t0 ein:');
y0=input('Gib hier y0 ein:');
tend=input('Bis zu welchem Wert von t möchtest du y annährn?');
n=input('Gib hier die Anzahl der Schritte ein(n):');
fstrich=input('Wie lautet die Differentialgleichung?', 's');
f=inline('fstrich');
dt=(tend-t0)/n;
t(1)=t0;
y(1)=y0;
for i=1:n
t(i+1)=t(i)+dt;
y(i+1)=y(i)+f(t(i),y(i))*dt;


rotdim([flip(t) ; flip(y)])
scatter(t,y,'*')
hold on
f=inline('fstrich');
t=t0:0.001:tend;
y=lsode('f',y0,t);
plot(t,y)

有人看到错误或可以更改的地方吗?

1 个答案:

答案 0 :(得分:1)

显然您更新了八度。

f=inline('fstrich'); % this is discouraged
y=lsode('f',y0,t); % and this is not valid anymore. 

相反,创建一个匿名函数

f=str2func(fstrich);
y=lsode(f,y0,t);