2016-04-28 5 views
0

Ich bin neu bei MATLAB und ich versuche herauszufinden, um eine Differentialgleichung zu lösen. Meine Gleichung lautet: d^2x/dt^2 - sin (t) * (dx/dt) = x. Ich versuche für t = 10 zu lösen und nehme an, dass die Anfangswerte für t = 0 angegeben sind. Ich habe keine Ahnung, wo ich anfangen soll. Jede Hilfe wäre großartig.Differentialgleichung MATLAB2

+0

[ 'ode45' Beispiel] (http: //www.mathworks.com/help/matlab/ref/ode45.html#bu3uj8b). – TroyHaskin

+0

Sie können [diesen Blogbeitrag] (http://blogs.mathworks.com/loren/2013/06/10/from-symbolic-differential-equations-to-their-numeric-solution/) von The MathWorks aufschlussreich finden. – horchler

Antwort

0

Ich empfehle die Verwendung von State-Space-Modellierungssyntax, wobei wir x als Vektor unserer Zustandsvariablen (x) und ihrer nachfolgenden Ableitung behandeln.

Hier ist Beispielcode Ihr Anfangswertproblem zu lösen:
(I verwendet FreeMat, aber es sollte für MATLAB sein)

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