2016-04-28 34 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-the-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

関連する問題