Analytical solution of ODEs

5 vues (au cours des 30 derniers jours)
Umar Ashraf
Umar Ashraf le 12 Août 2016
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
Torsten
Torsten le 12 Août 2016
The code is for the ODE
dx/dt = -2*x
x(0) = 1
Best wishes
Torsten.

Connectez-vous pour commenter.

Réponses (2)

Star Strider
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
Torsten
Torsten le 12 Août 2016
x(t) = 8*exp(-2*t)
Best wishes
Torsten.
Star Strider
Star Strider le 12 Août 2016
Correct.
I forgot the initial condition.
Still waking up here (UCT-6).

Connectez-vous pour commenter.


alex mloso
alex mloso le 22 Juil 2021
A =

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by