Need help with Euler's method differential equations

3 Ansichten (letzte 30 Tage)
Thomas Stolpe
Thomas Stolpe am 13 Sep. 2018
Kommentiert: Torsten am 13 Sep. 2018
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 Kommentar
Torsten
Torsten am 13 Sep. 2018
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.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Mathematics finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by