help-octave
[Top][All Lists]
Advanced

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

Re: getting values from functions, global designation error


From: Jaroslav Hajek
Subject: Re: getting values from functions, global designation error
Date: Wed, 1 Apr 2009 11:37:55 +0200

On Wed, Apr 1, 2009 at 11:11 AM, Jim Maas <address@hidden> wrote:
> I'm trying to set a variable as global, so I can use the value of it in
> the main script but keep getting this error message. What am I doing wrong?
>

It says it all. You're trying to declare an output variable global,
which makes no sense.

> I also need to get the value of ca (at each iteration) so I can use it
> in the main script. When I try to plot it from the main script, I just
> get an error saying that the variable 'ca' has not been assigned. I need
> the actual value of ca at each iteration, not the integrated value of
> ca, which would happen if I put ca in the dydt matrix, because it would
> then get integrated by the ode45 procedure.
>
> just syntax I realize ... still haven't got it.
>
> Thanks
>
> Jim
>
> --------------------------
> error: can't make function parameter `ca' global
> error: evaluating global command near line 3, column 3
> error: called from `mmodes' in file
> `/home/jamaas/Resarch/Octave/Buckengr210/mmodes.m'
> error: evaluating assignment expression near line 328, column 17
> error: evaluating if command near line 317, column 7
> error: evaluating for command near line 314, column 5
> error: evaluating while command near line 303, column 3
> error: called from `ode45' in file
> `/usr/share/octave/packages/3.0/odepkg-0.6.4/ode45.m'
> error: near line 8 of file `jim1.m'
> -----------------------------------------------
> Here is the function .m file
> -------------------------------------------------
> function [dydt,ca,out] = mmodes(t,y)
>
> global ca out
>
> % Solve the kinetics example
>
> dydt = zeros(size(y));
>
> % Parameters - reaction-rate constants
>
> k1 = 5.0; k2 = 2.0; k3 = 1.0; sz = 15.37; km = 0.496; vmax = 4.317;
>
> A = y(1);
> B = y(2);
> C = y(3);
>
> ca = A / sz;
> out = vmax / (1 + ( km /ca));
> ca1 = ca';
>
> % Evaluate the RHS expression
>
> % dydt(1) = -k1*A + k2*B;
> dydt(1) = -out + k2*B;
> dydt(2) = out - (k2+k3)*B;
> dydt(3) = k3*B;
>
> % eof - mmodes.m
>
>
>
> ----
> Jim Maas
>

Judging by your poor description of the problem (please restate
everything important if you're posting a new topic, even if it is
closely related to an older one), I wildly guess that you want to do
something like

function dydt = mmodes(t,y)
global ca out
...
ca(end+1) = A / sz;
out = vmax / (1 + (km/ca(end)));
...

endfunction

....
global ca out
out = ca = [];

ode45 (@mmodes, ...)
...
plot (t, ca);
...

here, the values ca and out will be accumulated in a global array.

hth

-- 
RNDr. Jaroslav Hajek
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz


reply via email to

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