2010-07-24 279 views

回答

7

首先,您必須減少訂單。令z = Y '=> Z'= Y」

你ODE就變成

z' = sqrt(-2*z - 3*y + sin(x)), with z(0) = 0 
y' = z, with y(0) = 1 

現在你可以寫在MATLAB函數來表示此ODE:(其中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 

然後,您可以調用該函數如下:

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