Need help with Euler's method differential equations

2 ビュー (過去 30 日間)
Thomas Stolpe
Thomas Stolpe 2018 年 9 月 13 日
コメント済み: Torsten 2018 年 9 月 13 日
This is for academic purposes My differential equation is y' = 0.2 -3y
The prompt is in the attached image
I am not sure if I am doing this correctly or not. My professor does not help us with matlab at all (It is a math and matlab course combined, he just teaches us math and expects us to know matlab), is volunteering as the professor, does not reply to my emails, has no office hours, and barely speaks english :(
Here is my attempt:
function [] = WS3_Last_First ()
% y' = 0.2 - 3y
y0 = 1;
tEnd = 5;
h = 0.1;
N = (tEnd-t0)/h;
Y = zeros(N+1,1);
Y(1) = y0;
for i = 1:N
fi = 0.2 - 3 * Y(i);
Y(i+1) = Y(i) + h*fi;
end
end
plot(T,Y);
end
  1 件のコメント
Torsten
Torsten 2018 年 9 月 13 日
1. You don't define t0.
2. You will have to deduce h from N, not vice versa.
3. What is A in the exercise ? This variable (maybe y0 in your notation) should appear somewhere in your code.
4. The function should return Y (which you should rename in ySol).
Best wishes
Torsten.

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

回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by