Created
June 12, 2019 08:21
-
-
Save mrfarhadir/f1a67d5cea8f2edc510f4153c163b0af to your computer and use it in GitHub Desktop.
Euler method
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
% matlab eular method | |
% Author: Farhad Mehryari | |
% blog.mrfarhad.ir | |
function [y t] = euler(f,a,b,ya,n) | |
h = (b - a) / n; | |
y(1,:) = ya; | |
t(1) = a; | |
for i = 1 : n | |
y(i+1,:) = y(i,:) + h * f(t(i),y(i,:)); | |
t(i+1) = t(i) + h; | |
end; | |
% Author: Farhad Mehryari | |
% blog.mrfarhad.ir |
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
% matlab eular method | |
% Author: Farhad Mehryari | |
% blog.mrfarhad.ir | |
% USAGE : | |
f=inline('sin(y*t)','t','y'); | |
y=euler(f,0,1,1,10) | |
% OUTPUT : | |
y = | |
1.0000 | |
1.0000 | |
1.0100 | |
1.0300 | |
1.0605 | |
1.1016 | |
1.1540 | |
1.2178 | |
1.2931 | |
1.3790 | |
1.4737 | |
% Author: Farhad Mehryari | |
% blog.mrfarhad.ir |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment