Analytical solution of ODEs
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi everyone, I have a question regarding the analytical solution of the ODE`s. I have an ODE like "dx/dt = -2*x" with x = 8 at t = 0 and I have to solve it using Euler Method and Analytically on Matlab. Luckily, my friend got the solution of the code which is given as below. I am clear about Euler solution but can anyone explain that how he has solved it analytically? It will be a lot of help to me!
So if I need to solve other ODEs, How I can solve it? Like dx/dt = -4/x with x = 8 at t = 0.
clear all close all
h=1; % dxdt = -2*x; x(1) = 1;
t=[0:h:8];
for i=1:length(t)-1
x(i+1) = x(i) + -2*x(i)*h;
end
texact = [0:0.02:8];
xexact = exp(-2.*texact);
% size(x)
% size(t)
plot(t,x)
hold on
plot(texact,xexact,'k-.')
legend('numerical','analytical')
1 commentaire
Réponses (2)
Star Strider
le 12 Août 2016
Modifié(e) : Star Strider
le 12 Août 2016
It’s a simple separable first-degree differential equation:
dx/dt = -2*x
dx/x = -2*dt —> integrate both sides to get:
log(x(t)) = -2*t
x(t) = exp(-2*t)
Q.E.D.
2 commentaires
Voir également
Catégories
En savoir plus sur Ordinary Differential Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!