把梦想照进现实

Matlab ode45的两道计算

2016.11.22

Two Questions

Q1

odefun=@(x,y)x*sin(y)-sin(x)
[x,y]=ode45(odefun,[0,5],0.5)
plot(x,y)

Q2

Fisrt define a function:

function dy=rigid(x,y)
dy=zeros(2,1);
dy(1)=2*x*y(1)*y(2);
dy(2)=y(1)^2+y(2)^2;
end

And then:

[x,y]=ode45('rigid',[0,5],[0.2,-0.1],0.01)
plot(x,y(:,1),'r',x,(y(:,2)),'black')

The Result:

Comments
Write a Comment