Need help with Euler's method differential equations

2 vues (au cours des 30 derniers jours)
Thomas Stolpe
Thomas Stolpe le 13 Sep 2018
Commenté : Torsten le 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 commentaire
Torsten
Torsten le 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.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Mathematics dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by