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
0 个评论
采纳的回答
Rafael Hernandez-Walls
2020-9-25
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 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!