Skip to content

Commit

Permalink
Create euler_method_example.m
Browse files Browse the repository at this point in the history
  • Loading branch information
angeloyeo committed May 24, 2021
1 parent 5bce31f commit 1d9d91f
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions 미적분학/미분방정식/euler_method_example.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
% Eulerian Method
% Setup and initial conditions
h = 0.00025; % step size
x = 0:h:5; % interval of x
y = zeros(size(x)); % allocate the resulting y
ys = linspace(0.5, 1.5, 10);
close all;
figure;
for i_ys = 1:length(ys)
y(1) = ys(i_ys); % inizial value of y
n = numel(y); % the number of y values
% The loop that solves the differential equation:
for i=1:n-1
f = (y(i)-2*sin(x(i)));
y(i+1) = y(i) + h * f;
end
hold on
plot(x, y, 'b', 'DisplayName', 'Euler method');
end

0 comments on commit 1d9d91f

Please sign in to comment.