필터 지우기
필터 지우기

Converting Euler's method calculation into matlab

조회 수: 2 (최근 30일)
Dai Nguyen
Dai Nguyen 2020년 9월 25일
댓글: Dai Nguyen 2020년 9월 25일
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
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개)

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by