help-octave
[Top][All Lists]
Advanced

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

Re: Integration with constants?


From: Søren Hauberg
Subject: Re: Integration with constants?
Date: Mon, 13 Nov 2006 10:33:44 +0100
User-agent: Thunderbird 1.5.0.7 (X11/20060918)

You also need to make alpha global inside your function. So you function should look something like this:

function res = Ji1(x)
   global alpha; ## This line is the only difference
   res = log( ...
     ( sqrt(1 + alpha.^2 + 2.*alpha.*cos(x)) + 1 + alpha.*cos(x) ) ./ ...
     ( sqrt(1 + alpha.^2 + 2.*alpha.*cos(x)) + alpha.*sin(x) - 1 ) )
end

I haven't tested it, but I think it should help...

Søren

Jens Benecke skrev:
John W. Eaton wrote:

| > | [J2, ier, nf,   err] = quad(@(x) log( ...
| > |         sqrt(1 + alpha.^2 + 2.*a.pha.*cos(2.*x)) + alpha + cos(2.*x)
| > |         ), 0, pi/2, 1e-6)
| > | "alpha" is a constant that has been calculated before. However,
| > | Octave tells me "error: alpha undefined ..."

| Sorry ... 2.1.72, on SuSE Linux.
| Any way to do this with the 2.1 branch?

In that case, I think the only option is a separate function and
global variables.

Hi,

I tried this - setting "alpha" to global, then executing my function:

38 global alpha = R2./R1                -> returns 1.2286
39 kii = sqrt(4.*alpha ./ (1+alpha).^2) -> works fine
40 41 isglobal('alpha') -> returns 1 42 function res = Ji1(x) 43 res = log( ...
44      ( sqrt(1 + alpha.^2 + 2.*alpha.*cos(x)) + 1 + alpha.*cos(x) ) ./ ...
45      ( sqrt(1 + alpha.^2 + 2.*alpha.*cos(x)) + alpha.*sin(x) - 1 ) )
46 end
47 48 [J1, ier, nf, err] = quad('Ji1(x)', 0, pi/2, 1e-6)


Result:

error: `alpha' undefined near line 44 column 13
error: evaluating binary operator `.^' near line 44, column 18
error: evaluating binary operator `+' near line 44, column 11
error: evaluating binary operator `+' near line 44, column 22
error: evaluating argument list element number 1
error: evaluating binary operator `+' near line 44, column 42
error: evaluating binary operator `+' near line 44, column 46
error: evaluating binary operator `./' near line 44, column 64
error: evaluating argument list element number 1
error: evaluating assignment expression near line 43, column 5
error: called from `Ji1'
error: evaluating assignment expression near line 48, column 34
error: called from `__quad_fcn_Q__'
error: quad: evaluation of user-supplied function failed


I'm a bit lost here... =;()





reply via email to

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