简体   繁体   English

解决ODE45 -Matlab

[英]Solving in ODE45 -Matlab

I have an ODE, y'=y^2+y ; 我有一个ODE, y'=y^2+y ; So, I wrote an script as: 因此,我将脚本编写为:

foo=@(y)(y.^2+y);
[x y]=ode45(foo,[1 4],1);

But it returns the following error: 但它返回以下错误:

Error using @(y)(y.^2+y)
Too many input arguments.

Error in odearguments (line 88)
f0 = feval(ode,t0,y0,args{:});   % ODE15I sets args{1}
to yp0.

Error in ode45 (line 114)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0,
odeArgs, odeFcn, ...

I must have made some mistake in defining function. 我在定义函数时肯定犯了一些错误。 I appreciate any comments and suggestions. 我感谢任何意见和建议。

Quoting the official documentation : 引用官方文件

All solvers solve systems of equations in the form y′ = f(t,y) or problems that involve a mass matrix, M(t,y)y′ = f(t,y). 所有求解器都以y′ = f(t,y)形式解决方程组或涉及质量矩阵M(t,y)y′ = f(t,y).

Your function accepts only one variable y , whereas it must accept two: t and y . 您的函数仅接受一个变量y ,而必须接受两个变量: ty So, if your ODE is y′ = y 2 + y , define foo in the following manner: 因此,如果您的ODE为y′ = y 2 + y ,则可以通过以下方式定义foo

foo = @(t, y)(y .^ 2 + y);

and it should work. 它应该工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM