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

回答(1 个)

Torsten
Torsten 2018-11-28
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

类别

帮助中心File Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息

提问:

2018-11-28

回答:

2018-11-28

Community Treasure Hunt

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

Start Hunting!

Translated by