help-octave
[Top][All Lists]
Advanced

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

Re: Bi variate to mono variate functions


From: Thomas Shores
Subject: Re: Bi variate to mono variate functions
Date: Wed, 29 Mar 2006 11:41:28 +0000
User-agent: KMail/1.8

On Wednesday 29 March 2006 15:32, David Bateman wrote:
> Anglade Pierre-Matthieu wrote:
> >Hi all,
> >
> >I've some kind of very dumb problem with octave's synthax.
> > probably because I don't mastered it at all I'm not able to
> > solve the following problem:
> >
> >I have a function which look like having two variables but have
> > in fact a single one and I can't find the way to tell this to
> > octave. Here is the function (LateX form):
> >f(x) = \int_a^b g(x,y) dy
> >
> >In order to compute that I first define g(x,y)
> >Then I'd like to use the "quad" function to get the integral
> > over the range o "y" values.
> >but I d'ont find the way to tell quad that my function is now
> > g(x,y) but with a fixed "x" value.
> >
> >Obviously I need to do this on the fly ( i.e. I can't define a
> >function for each value of x) because otherwise it would take
> > too long to get a complete plot...
> >
> >Could anybody kindly help me?
> >
> >
> >--
> >Pierre-Matthieu Anglade
>
> There is currently no way to do this, though funnily I just
> implemented it with the attached patch I'm working on in another
> thread about importing octave-forge changes into octave. So if
> you want to rebuild octave the you have the patch :-)
>
> D.

True, you can't do it in a straightforward manner, but if you're 
willing to live with globals, you can get this job done by creating 
only one auxiliary wrapper function once and for all:

octave:2> global x
octave:3> function retval = gx(y)
> global x
> retval = g(x,y);
> end
octave:4> % now make up any g(x,y) you want, but not anonymous
octave:4> function retval = g(x,y)
> retval = x.^2 +y.^2;
> end
octave:5> x = 1;
octave:6> quad('gx',0,1)
ans = 1.3333
octave:7> x = 0;
octave:8> quad('gx',0,1)
ans = 0.33333






-------------------------------------------------------------
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]