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

Antworten (1)

Torsten
Torsten am 28 Nov. 2018

0 Stimmen

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

Kategorien

Mehr zu Numerical Integration and Differential Equations finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 28 Nov. 2018

Beantwortet:

am 28 Nov. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by