Created
November 23, 2019 18:10
-
-
Save mrfarhadir/019c419b854fba5fd9e72fb898d2dace to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ImprovedEuler(F) | |
% Improved Euler Method | |
% blog.mrfarhad.ir | |
% author: Farhad Mehryari | |
a = 0; | |
b = 200; | |
% محدوده مورد نظر | |
n = 100; % ـعداد دفعات تکرار حلقه | |
h = (b - a)/n; % طول هر مرحله | |
N(1) = 0.5; % مقدار اولیه N | |
t(1) = a; % مقدار اولیه t | |
for i=1:n | |
N(i+1) = N(i) + h*F(N(i),t(i)); | |
t(i+1) = a + i*h; | |
N(i+1) = N(i) + 0.5*h*(F(N(i+1), t(i+1)) + F(N(i),t(i))) ; | |
end | |
disp(N) % نمایش بردار جواب های هر مرحله | |
end | |
% blog.mrfarhad.ir | |
% author: Farhad Mehryari |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
F = @(N, t) .02*(1 - N/2)*N; | |
ImprovedEuler(F) | |
Columns 1 through 8: | |
0.50000 0.51515 0.53059 0.54633 0.56235 0.57866 0.59525 0.61210 | |
Columns 9 through 16: | |
0.62922 0.64660 0.66422 0.68208 0.70017 0.71848 0.73700 0.75571 | |
Columns 17 through 24: | |
0.77460 0.79367 0.81289 0.83226 0.85176 0.87137 0.89109 0.91089 | |
Columns 25 through 32: | |
0.93076 0.95069 0.97066 0.99065 1.01065 1.03064 1.05060 1.07053 | |
Columns 33 through 40: | |
1.09039 1.11019 1.12990 1.14951 1.16900 1.18836 1.20757 1.22663 | |
Columns 41 through 48: | |
1.24551 1.26421 1.28271 1.30101 1.31908 1.33693 1.35453 1.37189 | |
Columns 49 through 56: | |
1.38900 1.40583 1.42240 1.43869 1.45470 1.47042 1.48584 1.50097 | |
Columns 57 through 64: | |
1.51580 1.53032 1.54454 1.55846 1.57207 1.58536 1.59836 1.61104 | |
Columns 65 through 72: | |
1.62342 1.63549 1.64726 1.65873 1.66990 1.68078 1.69136 1.70166 | |
Columns 73 through 80: | |
1.71167 1.72139 1.73085 1.74003 1.74894 1.75759 1.76598 1.77412 | |
Columns 81 through 88: | |
1.78201 1.78966 1.79707 1.80424 1.81119 1.81792 1.82443 1.83073 | |
Columns 89 through 96: | |
1.83683 1.84272 1.84842 1.85393 1.85925 1.86439 1.86936 1.87416 | |
Columns 97 through 101: | |
1.87880 1.88327 1.88759 1.89176 1.89578 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment