MATLAB: Solve a non linear differential equation

differential equations

Hello,
I have an equation like: Az"+Bz'+Cz'sin(Dz+E)+Fz=G with A,B,C,D,E,F,G are constant, and initial conditions known.
I have to solve it using Matlab, but I really don't know how to do, even after looking for information on Internet, could you help me or tell me what function I have to use?
Thank you in advance,
Romain CHAUDET

Best Answer

You can find the technique of creating a companion matrix from a differential equation in most differential equation textbooks, so I will spare you the discussion here.
[A,B,C,D,E,F,G] = deal(3,5,7,11,13,17,19);
odez = @(t,z) [z(2); (-B.*z(2)-C.*z(2).*sin(D*z(1)+E)-F.*z(1)+G)./A];
ts = linspace(1, 10, 250);
[t,z] = ode45(odez, ts, [0; 0]);
figure(1)
plot(t, z)
grid
legend('z(t)', 'z’(t)')