D'abord, vous devez réduire la commande. Soit z = y '=> z' = y »
Votre ODE devient alors
z' = sqrt(-2*z - 3*y + sin(x)), with z(0) = 0
y' = z, with y(0) = 1
Vous pouvez maintenant écrire une fonction Matlab pour représenter ce ODE: (où M = [zy] ')
function dMdx = odefunc(x,M)
z = M(1);
y = M(2);
dMdx(1) = sqrt(-2*z - 3*y + sin(x));
dMdx(2) = z;
end
Vous pouvez ensuite appeler cette fonction comme suit:
M0 = [ 0 1 ]; % Initial values of ODE
tfinal = 12; % Final integration time
[x,M] = ode45(@odefunc,[0 tfinal],M0) % Integration using the RK-45 algorithm