ode45('fun',[],[]) 中的函数如何调用外部参数。

3 visualizaciones (últimos 30 días)
rezionop
rezionop el 17 de Mayo de 2023
Respondida: chfikmoe el 17 de Mayo de 2023
我想利用ode45函数求解一个方程组,方程组中一个方程的系数的参数来自函数外部,不管怎样都无法调用,请问应该如何解决?function dy=fun(t,y,a)
dy=zeros(2,1);
dy(1)=sin(y(2));
dy(2)=a(4)+a(3)*t+a(2)*t.^2+a(1)*t.^3;
[t,f]=ode45('fun',[t0 tf],[y0 yf],a);
运行一直出错
错误提示:
Attempted to access a(4); index out of bounds because numel(a)=0.

Respuesta aceptada

chfikmoe
chfikmoe el 17 de Mayo de 2023
试试
[t,f]=ode45(@(t,y)fun(t,y,a),[t0 tf],[y0 yf]);

Más respuestas (0)

Categorías

Más información sobre 矩阵和数组 en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!