这个微分方程组初值是0,a和n的值需要每次定义,第二张图片是我现在用的子函数,但是因为每次n取值不一样,每次都要编写新的方程,有什么比较方便的方法可以解这个微分方程组??

 Respuesta aceptada

0 votos

function dy = odefun(t,y,a,n)
dy=zeros(n,1);
dy(1)=a*(35-2*y(1)+y(2));
for i=2:n-1
dy(i)=a*(y(i-1)-2*y(i)+y(i+1));
end
dy(n)=a*(y(n-1)-y(n));
a=2;n=6;
[t,y]=ode45(@(t,y)odefun(t,y,a,n),[0 5],zeros(1,n));

Más respuestas (0)

Categorías

Más información sobre App 构建 en Centro de ayuda y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!