关于ode求微分方程组数值解的问题。

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

 Accepted Answer

0 votes

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

More Answers (0)

Categories

Find more on App 构建 in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!