Converting Euler's method calculation into matlab

1 次查看(过去 30 天)
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
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by