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에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!