# Converting Euler's method calculation into matlab

2 views (last 30 days)
Dai Nguyen on 25 Sep 2020
Commented: Dai Nguyen on 25 Sep 2020
Hi I wanna use Matlab to solver for an Euler calculation with the range of t from 0 to 10 with 0.5 step. however for some reason my code isn't working. The initial y=0
this is the equation dy/dt=(3*Q/A*(sin(x))^2))-(alpha*(1+y)^1.5)/Q
% Euler's Method
% Initial conditions and setup
Q=400
A=1200
alph=160
h = 0.5; % step size
t = 0:0.5:10; % the range of t
y = zeros(size(t)); % allocate the result y
y(1) = 0; % the initial y value
n = numel(y); % the number of y values
% The loop to solve the DE
for i=1:n-1
f = (3*(Q/A)*(sin(t))^2)-((alph*(1+y(i))^1.5)/A)
y(i+1) = y(i) + h * f;
end
plot(x,y); grid on

Rafael Hernandez-Walls on 25 Sep 2020
tray this:
% Initial conditions and setup
Q=400;
A=1200;
alph=160;
h = 0.5; % step size
t = 0:0.5:10; % the range of t
y = zeros(size(t)); % allocate the result y
y(1) = 0; % the initial y value
n = numel(y); % the number of y values
% The loop to solve the DE
for i=1:n-1 % v---- t fot t(i)
f = (3*(Q/A)*(sin(t(i))).^2)-((alph*(1+y(i)).^1.5)/A);
y(i+1) = y(i) + h * f;
end
plot(t,y); grid on
Dai Nguyen on 25 Sep 2020
Thank you so much

### Categories

Find more on Axes Transformations in Help Center and File Exchange

R2020b

### Community Treasure Hunt

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

Start Hunting!