help-octave
[Top][All Lists]
Advanced

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

Re: bessel functions with octave


From: Bård Skaflestad
Subject: Re: bessel functions with octave
Date: Wed, 17 Aug 2011 21:50:08 +0200

On Wed, 2011-08-17 at 20:24 +0200, Bård Skaflestad wrote:
> On Wed, 2011-08-17 at 19:51 +0200, john wrote:
> > Hi,
> > 
> > concerning my question from 16/08/2011
> 
> > [i.e., "How to compute integral approximation of J0(x) by means of QUADL"]

> >  I did the following [context restored]:
> > 

        function y = besintj0(x)
          global x
          y = 1 / pi * quadl(@bintegra, 0, pi);
        endfunction
        
        function y = bintegra(q)
          global x
          y = cos(x .* sin(q));
        endfunction

Right.  Sorry about failing to get the proper details before.  I'm a
little bit unsure about the actual rules (it's been too long since I
used it), but I believe that to actually use a GLOBAL symbol, you have
to declare the symbol as such also in the outer-most scope (typically on
the command line or in a *script*).  I'll be happy about any
clarification or confirmation about this.

In any case, having a GLOBAL of the same name as a parameter (or local
variable) is generally not recommended.  One will override the other but
I don't recall which takes priority.  Anyway, as I alluded to earlier,
your 'besintj0' function can be implemented simply as a function handle:

    besintj0 = @(x) quadl(@(q) cos(x .* sin(q)), 0, pi) / pi;

Using this definition you get

octave:1> besintj0 = @(x) quadl(@(q) cos(x .* sin(q)), 0, pi) / pi;
octave:2> format long e, [besselj(0, 3) ; besintj0(3)], format
ans =

  -2.60051954901934e-01
  -2.60051954901933e-01


Sincerely,
-- 
Bård Skaflestad <address@hidden>
SINTEF ICT, Applied Mathematics



reply via email to

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