Solution
Solution
Solution
syms y(x)
dsolve(y*diff(y)==x-1, y(0)==1)
ans =
dsolve(diff(y,x,2)-x*diff(y,x)-y==0)
ans =
Lorenz equations
a=10;
b=8/3;
c=28;
1
%x [x y z]
myode= @(t,x) [a*(x(2)-x(1)); x(1)*(c-x(3))-x(2);...
x(1)*x(2)-b*x(3)];
ts=[0 100];
x0=[0 1 0];
[t,x]=ode45(myode,ts,x0);
plot(x(:,1),x(:,3))
t(end),x(end,:)
ans = 100
ans = 1×3
-12.5668 -21.2013 19.9384
Planetary motion
k=1;
%z =[x y u v]
myode =@(t,z) [z(3); z(4); ...
-k*z(1)/(z(1)^2+z(2)^2)^(3/2);...
-k*z(2)/(z(1)^2+z(2)^2)^(3/2)];
ts=[0 50];
2
z0 =[1 0 0 0.2];
options=odeset('AbsTol',1.e-9,'RelTol',1.e-8);
[t,z]=ode45(myode,ts,z0,options);
plot(z(:,1),z(:,2))
ener=0.5*(z(:,3).^2+z(:,4).^2)- k./sqrt(z(:,1).^2+z(:,2).^2);
plot(t,ener)
axis equal
3
4