On Monday, November 18, 2013 7:26:08 AM UTC+13, Roger wrote:
> I am trying to run the Euler method script for the DE y'=y, y(0)=1 taking 4 steps.
>
>
>
> I type at the command prompt euler3(rhs, 1, 1, 0.25, 4.0)
>
> and I get the following error:
>
>
>
> Error using rhs (line 7)
>
> Not enough input arguments.
>
>
>
> Can anyone tell me how to get this script to work or what this error is?
>
> Thank you in advance for your help.
>
>
>
> The code I am using is:
>
>
>
> function [tout, yout] = euler3(rhs, t0, y0, h, N)
>
>
>
> % euler('rhs',t0,y0,h,N)
>
> %
>
> % integrates a single ordinary differential equation
>
> % of the form
>
> % y'=f(t,y)
>
> % where
>
> % the initial value of t = t0
>
> % and y(t0) = y0
>
> % the stepsize = h
>
> % and the number of steps = N
>
> % Note: the right hand side must be defined in the file rhs.m
>
>
>
> % allocate space and initialize to vectors to zero
>
> tout = zeros(N+1,1);
>
> yout = zeros(N+1,1);
>
>
>
> % set initial values
>
> tout(1) = t0;
>
> yout(1) = y0;
>
>
>
> % apply Euler's method
>
> for i=1:N
>
> tout(i+1) = tout(i) + h;
>
> slope = feval(rhs,tout(i),yout(i));
>
> yout(i+1) = yout(i) + slope*h;
>
> end
>
>
>
> and the rhs.m file is:
>
> function yprime = rhs(x, y)
>
>
>
> % rhs returns a function which is the right hand side
>
> % of a first order differential equation
>
> % dy/dx = y' = f(x,y)
>
>
>
> yprime = x*y;
Compare these two lines:
euler3(rhs, 1, 1, 0.25, 4.0)
% euler('rhs',t0,y0,h,N)
The first is what you say you type in,
The second is from your very own documentation.
Can you see the difference (apart from the suffix 3)?
Clue: at the command prompt type rhs
