help-octave
[Top][All Lists]
Advanced

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

Re: function definition for integration


From: Paul Thomas
Subject: Re: function definition for integration
Date: Tue, 23 Mar 2004 08:36:44 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20030225

Dear All,

quad, in the other product, is one of the "function functions" that can feed parameter values to the called function via its own arguments. I do not recall exactly how it goes but it is something like:

[integral err other_stuff] = quad("my_integrand", lower_x , upper_x , prec , verbose , P1 , P2 .... PN);

with

function out_val = my_integrand( x , P1 , P2 , .....  PN);

I already ran into this when porting a programme and used a wrapper with the parameters fed via global to fix it. Is this somewhere that we should go for compatibility? Note though that the fifth argument is already different in octave.

Paul T

Paul Kienzle wrote:

Or you can include the value of the fixed parameters
directly in your wrapper function:

    function x=flotest1(a), x=flotest(a,4); end

You can use inline() from octave-forge as a shorthand for this:

    octave:4> quad(inline('flotest(x,4)'),0,1)
    ans = 4.3333

Paul Kienzle
address@hidden

On Mar 21, 2004, at 10:53 PM, address@hidden wrote:

Flo:

A simple if inelegant way to pass multivariate functions when only a
univariate function is expected is to use global variables and a wrapper
function.

That is, if your integrand function is

    function x = flotest (a, b) x = a^2 + b; endfunction

then write a wrapper:

    function x = flotest1 (a)
      global flotest_b
      x = flotest (a, flotest_b);
    endfunction

define the global variable

    octave> global flotest_b
    octave> flotest_b = 4;

and do the integration:
octave> quad ("flotest1", 0, 1);
    4.3333



On Fri, 19 Mar 2004 08:23 pm, address@hidden wrote:

Hi,
Am am using 2.1.40 since 1 week, like it so a far a lot, and would like to
integrate a function, defined as with
two variables, whereas I pass on one as number - so as a simple
example s.th. like this, which doesn't do the trick:

function x=test(a,b)
x= a^2 + b;
endfunction
quad('test(a,4)',0,1)

So how can I pass on variables not values on to a
defined function ? I
dont try to do anything symbolic. I looked around a good bit in the
documentation, but couldn't figure it out.

Any hints are appreciated,
Thanks a lot,
Flo



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






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