[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Problem defining global vars
From: |
Geraint Paul Bevan |
Subject: |
Re: Problem defining global vars |
Date: |
Wed, 30 Jun 2004 09:13:55 +0100 |
User-agent: |
Mozilla Thunderbird 0.5 (X11/20040306) |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Christian Renz wrote:
| I'm quite new to octave, so forgive me if this is an overly simple
| question. But I wasn't able to find the answer in the wiki or in the
| manual.
|
| When I run the following script, octave complains that a and b are
| undefined. Once I move the definitions inside the function f, everything
| works fine, however. Is there a way I can define a and b so they are
| recognized by f (when used via lsode)?
|
You need to declare a and b as global inside the function body as well
as defining them outside it:
function xdot = f(x, t)
global a;
global b;
xdot = a*x + b;
endfunction
You can find a description of how global variables work if you type
'help -i global' at the Octave prompt.
- --
Geraint Bevan
http://homepage.ntlworld.com/geraint.bevan
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iEYEARECAAYFAkDidkMACgkQcXV3N50QmNPwpwCgij+vB2BZyLUuiNHpoShUaNRZ
mx0An0+M6KypqbUCBewxktfDoMcGSLpG
=Rd1I
-----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
-------------------------------------------------------------