i am being asked to solve a problem by eulers method
显示 更早的评论
URGENT HELP NEEDED
given y'=y, and y(0)=2 on [0,1], exact sulution: y=2*exp(x) i was told to plot the exact solution vs Eulers solution on the same graph. Use a while loop to determine the value of n(number of intervals) to guarantee the maximum error between the exact solution and Euler is less than 10^-2.
回答(1 个)
James Tursa
2017-7-28
编辑:James Tursa
2017-7-28
See Euler's Method here:
https://en.wikipedia.org/wiki/Euler_method
Look at the examples. An outline to get you going on the basic method is:
n = number of intervals <-- you fill this in
h = some stepsize <-- you fill this in
y = zeros(1,n+1);
t = zeros(1,n+1);
y(1) = some initial value <-- you fill this in
t(1) = some initial value <-- you fill this in
for k=2:n+1
y(k) = y(k-1) + SOMETHING; <-- you fill in the SOMETHING
t(k) = t(k-1) + SOMETHING; <-- you fill in the SOMETHING
end
Then plot the results against the exact solution.
2 个评论
michael shoga
2017-7-28
James Tursa
2017-7-28
Get the basic Euler's method working first. Then you can worry about wrapping the code up in a while loop to determine n per the desired tolerance.
类别
在 帮助中心 和 File Exchange 中查找有关 Mathematics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!