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: Billings, Paul
Subject: RE: Bi variate to mono variate functions
Date: Thu, 30 Mar 2006 08:52:49 -1000

This technique is useful in some instances, but likely the fixed variable
will not be a constant:
o> x = linspace(0,1);
o> for(i=1:length(x))
o>   f = inline('g(x(i),y)');
o>   integ(i) = quad(f, 0, 1);
o> end;
This fails because 'x' is undefined.  I don't know if this is improved by D.
Bateman's recent mod.

Paul

> -----Original Message-----
> From: Geordie McBain [mailto:address@hidden
> Sent: Wednesday, March 29, 2006 1:31 PM
> To: Thomas Shores
> Cc: address@hidden; Anglade Pierre-Matthieu
> Subject: Re: Bi variate to mono variate functions
>
>
> Yes, you can use global, or also inline (in case you're worried about
> the things that might go wrong if you leave a global variable called x
> lying around):
>
>   octave2.9:1> function z = g (x, y), z = x.^2+y.^2; endfunction
>   octave2.9:2> quad (inline ("g (1, y)"), 0, 1)
>   ans = 1.3333
>   octave2.9:3> quad (inline ("g (2, y)"), 0, 1)
>   ans = 4.3333
>   octave2.9:4> quad (inline ("g (0, y)"), 0, 1)
>   ans = 0.33333
>
> I was going to write about these two solutions at wiki.octave.org but it
> seems from David Bateman's post that this will only be of historical
> interest.  (Well done, David.)
>
> On Wed, 2006-03-29 at 11:41 +0000, Thomas Shores wrote:
> > 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
> > -------------------------------------------------------------
> >
>
>
>
> -------------------------------------------------------------
> 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
> -------------------------------------------------------------



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