How to graph Euler's Method?

I'm not exactly sure how to make a Euler's Method equation in mathlab
I'm given then initial ODE with an initial condition:
dy/dt = y(2 - ty), y(0) = 1'
then i'm supposed to use t = 1, 1.5, 2, and 2.5 with
a) h = .01
b) h=.05
c) h = .1
function r = yexact(t,y0,h)
r = y0*(2-th);
t = 01:0.5:2.5;
plot(t,yexact(t,1,.01)
this is what i did and thats clearly wrong..any ideas?

댓글 수: 3

Walter Roberson
Walter Roberson 2013년 2월 26일
For one thing, t*h rather than th
Terry
Terry 2013년 2월 26일
i fixed all of the technical stuff but im still getting an error that says not enough input arguments
function r = yexact(t,y0,h)
r = y0*(2-th);
t = 01:0.5:2.5;
plot(t,yexact(t,1,.01)
The plot command is calling yexact (ans is missing a parenthesis). This plot command exists within the yexact function. It is going to get recursive and not likely what you intended.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2013년 2월 26일

0 개 추천

When a function has arguments, as yours does, you cannot run it by pressing F5 or using "run" from a menu. Instead you need to go down to the command line and invoke it, such as by
yexact(5:19, -9876, 1E-21)

카테고리

질문:

2013년 2월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by