Need help with Euler's method differential equations

조회 수: 3 (최근 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 CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by