Differential Equations using eulers method

1. Consider the ODE ?? ?? = −1.2? + 7? −0.3? ; ?(? = 0) = 3 The solution to the above IVP is ? = 70 9 ? −0.3? − 43 9 ? −1.2?
a. Plot the above solution between 0 ≤ ? ≤ 30
b. Solve the ODE numerically for the time span above using the Euler explicit method (not ode45 or any other MATLAB ode function) and study the accuracy of the solution with respect to the actual solution in a. For example, divide the range of t in 5, 10, 100, and 1000 intervals and solve the differential equation at for each of these cases. Let’s call these solutions ?5, ?10, ?100, ?1000. Plot these on the same plot as in a.
I understand for part A i'm just plotting t against the solution
but for part B do i need a loop to obtain y5 y10 y100 y1000 and how would i do that.
Thank you

Respuestas (1)

Torsten
Torsten el 28 de Nov. de 2018

0 votos

Yes, you need a loop:
n = [5 10 100 1000];
for i=1:numel(n)
n_actual = n(i);
deltat = 30/n_actual;
y(i,1) = 3.0;
for j = 2:n_actual
y(i,j) = y(i,j-1) + ... ?;
end
end

Categorías

Más información sobre Numerical Integration and Differential Equations en Centro de ayuda y File Exchange.

Preguntada:

el 28 de Nov. de 2018

Respondida:

el 28 de Nov. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by