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
2018년 11월 28일
0 개 추천
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에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!