2016-04-28 56 views
0

我是MATLAB新手,我试图找出求解微分方程的方法。我的方程是:d^2x/dt^2 - sin(t)*(dx/dt)= x。我试图解决t = 10,并假设初始值为t = 0指定。我不知道从哪里开始,任何帮助将是伟大的。微分方程MATLAB2

+0

['ode45'示例](HTTP: //www.mathworks.com/help/matlab/ref/ode45.html#bu3uj8b)。 – TroyHaskin

+0

您可能会从The MathWorks指导中找到[此博客文章](http://blogs.mathworks.com/loren/2013/06/10/from-symbolic-differential-equations-to-their-numeric-solution/)。 – horchler

回答

0

我推荐使用状态空间建模语法,我们将x作为状态变量(x)及其后续派生的向量。

这里的示例代码解决您的初始值问题:
(我用的FreeMat,但它应该是相同的MATLAB)

function [] = ode() 

% Time 
t_start = 0.0; 
t_final = 10.0; 

% Lets treat x as a vector 
% x(1) = x 
% x(2) = dx/dt (first derivative of x) 
x0 = [0.1; 0]; % Initial conditions 

options = odeset('AbsTol',1e-12,'RelTol',1e-6,'InitialStep',1e-6,'MaxStep',1e-2); % stepping tolerances 
[t,x] = ode45(@system, [t_start t_final], x0, options); % Run the differential equation solver 

hold on 
plot(t,x(:,1),'r-') 
plot(t,x(:,2),'b-') 
hold off 

end 

% Define the differential equation 
function dxdt = system(t,x) 

dxdt = [x(2); ... % derivative of x(1) is x(2) 
x(1) + sin(t)*x(2)]; % derivative of x(2) is x + sin(t)*dx/dt 

end 

Resulting plot