help-octave
[Top][All Lists]
Advanced

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

Re: How to plot an user-defined function?


From: Geraint Paul Bevan
Subject: Re: How to plot an user-defined function?
Date: Fri, 01 Aug 2003 20:36:24 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030624

Eric Chassande-Mottin wrote:
function y = f(t)
   y = exp(-0.5*t*t);
endfunction

function z = g(t)
   z = (1.0/sqrt(2.0*pi))*quad('f',-10.0, t, 1e-12);
endfunction



your functions f and g work only for arguments that are scalar (ie.,
single number)


The function f(t) could be modified to work with vectors easily enough,
by using "t.*t" instead of "t*t"

I think you will have to use a for loop for g(t) though.

This works:

octave> function y = f ( t )
> y = exp ( -0.5 * t .* t );
> endfunction
octave> function z = g ( t )
> for i = 1 : length ( t )
> z(i) = (1.0/sqrt(2.0*pi))*quad('f',-10.0, t(i), 1e-12);
> endfor
> endfunction
octave> t = linspace ( -10 , 10 , 2000 );
octave> plot (t , g(t))
octave>

(but erf is much faster).

--
Geraint Bevan
Department of Mechanical Engineering
University of Glasgow
Tel: +44 (0)141 330 5917




-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

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