Need help with Euler's method differential equations
2 次查看(过去 30 天)
显示 更早的评论
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
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 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!