フィルターのクリア

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
  1 件のコメント
Dai Nguyen
Dai Nguyen 2020 年 9 月 25 日
Thank you so much

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by