help-octave
[Top][All Lists]
Advanced

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

bessel functions with octave 3.2.4


From: john
Subject: bessel functions with octave 3.2.4
Date: Tue, 16 Aug 2011 10:21:47 -0700 (PDT)

Hi,

I downloaded three programs in matlab to compute the bessel function Jo(x)
first the main program besseljm.m

%-----------------------------------------------------------------------
% Approximate the Bessel function of the first kind of order 0
% via Taylor's series expansion.
% Instructor: Nam Sun Wang
%-----------------------------------------------------------------------

% Start fresh ----------------------------------------------------------
      clear all

% Print out a program header -------------------------------------------
      disp("Approximate the Bessel function via Taylor''s series ")
      disp("expansion, which fails for x far away from the point ")
      disp("of expansion around x=0.  This program is accurate to ")
      disp("about 5 significant figures for 0<x<10.")
      disp(' ')

% Input data -----------------------------------------------------------
      x = input("Enter x: ");

% Print out the results ------------------------------------------------
      disp(' ')
      disp(["Taylor''s series expansion gives:  ",
num2str(besj0(x))   ])
          disp(["integral def gives              :  ",
num2str(besintj0(x))])
      disp(["Compare to Matlab''s bessel(0,x) = ",
num2str(besselj(0,x))])


the taylor serie expansion works and also "compare to matlab
bessel(0,x)

I choose x=3 this fives Jo(3)=-0,26005

The besintjo don't work ,here the program


      function y=besintJ0(x)
%-----------------------------------------------------------------------
% Approximate the Bessel's function of the first kind of order zero
% via the following integral definition.
%   J0(x) = (1/pi)*integral (from 0 to pi) of cos(x*sin(q))*dq
% Programming Note:
%   For large values of x, apply the asymptotic approximation formula.
%     J0(x)=sqrt(2/pi/x)*cos(x-pi/4),  for x>25
% Instructor: Nam Sun Wang
%-----------------------------------------------------------------------

      global xx
%     pi = 3.141593  already defined in Matlab

% Pass x into the integrand through "common"
      xx = x;

% Call an integration routine to do the grunt work.
%     y = 1/pi * quad8('bintegra', 0, pi);  ... old
      y = 1/pi * quadl('bintegra', 0, pi);

I could'nt download 'bintegra' I got page error not avaible.
I changes this to the following=

common xx
function bintegra=f6(q);
bintegra=cos(xx*sin(q));
endfunction


and besintjo to

      function y=besintj0(x)
%-----------------------------------------------------------------------
% Approximate the Bessel's function of the first kind of order zero
% via the following integral definition.
%   J0(x) = (1/pi)*integral (from 0 to pi) of cos(x*sin(q))*dq
% Programming Note:
%   For large values of x, apply the asymptotic approximation formula.
%     J0(x)=sqrt(2/pi/x)*cos(x-pi/4),  for x>25
% Instructor: Nam Sun Wang
%-----------------------------------------------------------------------

      global xx
%     pi = 3.141593  already defined in Matlab

% Pass x into the integrand through "common"
      xx = x;
      
% Call an integration routine to do the grunt work.
%     y = 1/pi * quad8('bintegra', 0, pi);  ... old
       
      y = 1/pi * quadl('f6', 0, pi);

when I run the program besseljm  input=3

for besintjo I get an error:invalid call to script.

Exits "common" in octave I found nothing on the internet.

Can you figure out what's wrong with besintjo and f6

Thank you very much for the help.

--
View this message in context: 
http://octave.1599824.n4.nabble.com/bessel-functions-with-octave-3-2-4-tp3747834p3747834.html
Sent from the Octave - General mailing list archive at Nabble.com.


reply via email to

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