2010-07-24 219 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