How to get the function after solving the differential equation using Eulers method?
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Yokuna
le 21 Juin 2021
Modifié(e) : Sergey Kasyanov
le 21 Juin 2021
How to get the value of x1(t) and x2(t) from the set of equations?
Initial condition is x1=1 and x2=2
x1dot=x1 -x2;
x2dot=-x1+x2;
0 commentaires
Réponse acceptée
Sergey Kasyanov
le 21 Juin 2021
Modifié(e) : Sergey Kasyanov
le 21 Juin 2021
Hello!
A = [1, -1
-1, 1];
x0 = [1
2];
dx = [0
0];
time_step = 0.1;
time = 0 : time_step : 10;
x = [x0, nan(2, time(end) / time_step)];
%solving
for i = 1:size(x, 2)-1
dx = A*x0; %matrix form of equation system
x(:, i+1) = x(:, i) + time_step*dx;
end
% plot results
figure; hold on;
plot(time, x(1,:), 'DisplayName', 'X1');
plot(time, x(2,:), 'DisplayName', 'X2');
xtitle('time');
legend show
0 commentaires
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!