迭代时所调用的M文件里的常参数不会更新问题?。

我在编写一个循环程序时,需要调用一个M文件来求解微分方程组,要求每次迭代时,微分方程组的系数矩阵都要变化,这如何做到啊?或者是否有别的解决方法?求各位大神解决!
M文件(矩阵A,B不变,而矩阵或向量K0需要每次更新)
function dx=adpsimple1(t,x)
A=[1 0;0 0.5];B=[0.3;0.2];
(A-B*K0)*x;
end
>> K0=[10 10];[t1,z]=ode45('adpsimple1',t0,x0)
Undefined function or variable 'K0'.
Error in adpsimple1 (line 3)
(A-B*K0)*x;
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, ...

 Respuesta aceptada

saevae
saevae el 28 de Oct. de 2022

0 votos

function dx=adpsimple1(t,x)改成function dx=adpsimple1(t,x,K0)将K0作为参数传递进去不就行了吗,其他地方相应调整

Más respuestas (0)

Categorías

Más información sobre 编程 en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 28 de Oct. de 2022

Respondida:

el 28 de Oct. de 2022

Community Treasure Hunt

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

Start Hunting!