help-octave
[Top][All Lists]

## Re: fourier coefficient - quad with more arguments?

 From: Geraint Paul Bevan Subject: Re: fourier coefficient - quad with more arguments? Date: Tue, 28 Sep 2004 19:09:02 +0100 User-agent: Mozilla Thunderbird 0.7.1 (X11/20040715)

```-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Gerrit wrote:
| Hi,
|
| I'm trying to do something like this:
|

<cut>

|
| But I get:
|
| error: `k' undefined near line 8 column 15

You can pass k to the function as a global variable. You need to declare
it as such in the main workspace and within the function:

all_a = ones(1, 20);
global k;
for k = 1:20
~  function y = f(t)
~    global k;
~    x = mod(t, pi);
~    s = t*(pi-t);
~    y = s*cos(k*t);
~  endfunction
~  a = (2/pi) * quad('f', 0, pi);
~  all_a(k) = a
endfor

- --
Geraint Bevan
http://www.mech.gla.ac.uk/~gbevan

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iEYEARECAAYFAkFZqL4ACgkQcXV3N50QmNNFCgCgiKolEQisFdHsjSdAvkd9eMwL
hkEAn3TuVu3ijqgZMgyrnML2Y4KpfJZZ
=TWRO
-----END PGP SIGNATURE-----

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

```