【问题标题】:lsode function in octave八度音阶的 lsode 函数
【发布时间】:2020-12-31 12:49:53
【问题描述】:

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

"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)

有没有人发现错误或我可以更改的内容?

【问题讨论】:

  • 我把它改成了英文。很抱歉用德语发布。
  • “突然停止工作”一定有什么改变了。更新了软件版本?
  • 是的,似乎软件更新了,但我没有意识到这一点。

标签: octave equation dgl


【解决方案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);

【讨论】:

  • 我收到此错误:错误:@y/(1+t^2):没有找到函数和方法错误:在第 7 行第 2 列从 euler 调用 >>
  • @AdnZek 对,因为 y/(1+t^2) 确实无效。尝试@(y,t)( y/(1+t^2) ) 作为输入。
  • 它现在可以工作,但解决方案的情节是错误的。
  • 但这不是dgl初始值(-3/1)的解
  • 请停止发送垃圾邮件,我不是来为您服务的,我在空闲时间免费帮助您,请注意这一点。在您的代码中,您试图求解y 的方程。那么为什么y 是您输入的一部分?您的输入字符串不依赖于y 是否没有意义?我不确定你是否理解你想要做什么,但如果你这样做了,你能试着在原帖中解释一下吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-14
  • 2014-11-06
  • 1970-01-01
  • 2014-01-14
  • 2015-04-16
  • 1970-01-01
相关资源
最近更新 更多