help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

octave 3.2.4 functions


From: john
Subject: octave 3.2.4 functions
Date: Fri, 29 Jul 2011 06:45:16 -0700 (PDT)

Hi,

I have a problem to run the following programs with functions.It's concern
of solution of a diff.vgl and

eulers method for solving diff.vgl.
function y = rk2a( f, y0, t )
  % ----------------------------------------------------------------------
  % Jonathan R. Senning <address@hidden>
  % Gordon College
  % March 22, 1999
  %
  % Usage: y = rk2a(@f, y0, t)
  %
  % Returns:
  %     one-dimensional array of y values associated with the t values
  %     passed into the function.
  %
  % Parameters:
  %     f:      handle of function equal to dy/dt.
  %     y0:     y value corresponding to t(1), initial t value
  %     t:      array of points to evaluate solution at
  %
  % This function implements a 2nd order Runge-Kutta algorithm to solve the
  % initial value problem
  %
  %     dy
  %     -- = f(y,t),     y(t_0) = y_0
  %     dt
  % 
  % This particular version is based on the algorithm presented in
"Numerical
  % Analysis", 6th Edition, by Burden and Faires, Brooks-Cole, 1997.
  % ----------------------------------------------------------------------

  [m, n] = size( t );
  y = zeros( m, n );
  n = max( m, n );

  y(1) = y0;

  for i = 1 : n-1
    h = t(i+1) - t(i);
    k1 = h * f( y(i), t(i) ) / 2.0;
    y(i+1) = y(i) + h * f( y(i) + k1, t(i) + h / 2.0 );
  end

end
How do I run this program,I tried everything but no result.

----_--second program:
function xdot = f (x, t) 
 r = k = 1.4;
 a = 1.5;
  b = 0.16;
  c = 0.9;
  d = 0.8;
  xdot(1) = r*x(1)*(1 - x(1)/k) - a*x(1)*x(2)/(1 + b*x(1));
 xdot(2) = c*a*x(1)*x(2)/(1 + b*x(1)) - d*x(2);
 endfunction
 x0 = [1; 2];
t = linspace (0, 50, 200)';
x = lsode ("f", x0, t);
plot (t, x)

When I save this program as "function xdot" and I type function xdot at the
octave prompt
,no result.

I have a problem to save this functions and to run.

How can I save and run this programs????

Can you help me?

Thank you


--
View this message in context: 
http://octave.1599824.n4.nabble.com/octave-3-2-4-functions-tp3704094p3704094.html
Sent from the Octave - General mailing list archive at Nabble.com.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]