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: George Kousiouris
Subject: Re: getting values from functions, global designation error
Date: Wed, 01 Apr 2009 12:48:51 +0300
User-agent: Thunderbird 2.0.0.21 (Windows/20090302)

Hi,

At least in Matlab you can't pass a global variable from a function script to the main script. The best way to do it is by returning it through the function output.

Hope this helps

George

Jim Maas 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?

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


_______________________________________________
Help-octave mailing list
address@hidden
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave


reply via email to

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