help-octave
[Top][All Lists]
Advanced

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

Re: Global variables in function


From: LUK ShunTim
Subject: Re: Global variables in function
Date: Wed, 12 Nov 2008 14:52:43 +0800
User-agent: Mozilla-Thunderbird 2.0.0.17 (X11/20081018)

Corsair wrote:
> Hi all.  I have the follow code:
> 
>     global w = 2;
>     global C = 1;
>     global I = 1;
>     
>     function vr = r(t)
>       vr = [sin(w * t), cos(w*t), t];
>     endfunction
>     
>     function vt = tang(t)
>       vt = [w*cos(w*t), -w * sin(w*t), 1];
>     endfunction
>     
>     function db = dB(t, r)
>       db = I * cross(tang(t), f(t) - r) / norm(f(t) - r)^3;
>     endfunction
>     
>     dB(1, [1,2,3])
> 
> When I run this script, Octave told me that
> 
>     error: `w' undefined near line 12 column 9
>     error: evaluating binary operator `*' near line 12, column 10
>     error: evaluating assignment expression near line 12, column 6
>     error: called from `tang'
>     error: evaluating argument list element number 1
>     error: evaluating binary operator `*' near line 16, column 10
>     error: evaluating binary operator `/' near line 16, column 37
>     error: evaluating assignment expression near line 16, column 6
>     error: called from `dB'
>     error: near line 19 of file `test.oct'
> 
> Anyone know the problem?

You have to add

global w;

etc in your functions as well.

Regards,
ST
--


reply via email to

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