HP Forums

Full Version: Dynamic Variable(s)....Help??
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
how can i create a dynamic variable.?
Application:
in circuit simulation application (eNet) http://www.hpmuseum.org/forum/thread-7015.html i was able to generate a column dynamic matrix (nkll) for a given network.
nkll consist of node voltages and currents thru a branch variables. (but they were never declared as a variables in the application );
now i want to assign values (solutions) to nkll matrix in the application....help?
the goal here is designing a scope for these nodes:
Suppose M is the matrix.
Then you can treat M(i,j) as variables.
So in my opinion there is no need to create extra variables.
Hello,

You can create variable dynamically using HVars and AVars, However, in your case here, what you most likely need is the creation of one single variable that will contains an indexable number of variables.

If your data is purely numerical (reals or complex), a matrix will work. Else, you can use a list.

Cyrille
(11-21-2016 06:54 AM)cyrille de br├ębisson Wrote: [ -> ]Hello,

You can create variable dynamically using HVars and AVars, However, in your case here, what you most likely need is the creation of one single variable that will contains an indexable number of variables.

If your data is purely numerical (reals or complex), a matrix will work. Else, you can use a list.

Cyrille
... this is my work around for dynamic variable(s) that exist with their variable names.
with cas: create a dummy variable(s ) with expr, string syntax and assign zero to it. then use these dummy(s) which now exist in cas world in home/cas.
example is provided below...in my circuit case I know the number of node(s) hence create v1, v2....vn. I also know the paths hence I can create potential difference label as v1v2, v3v4.....and for current create j1j2, j3j4.....
a modification of this code dumber() with arguments can be tailored to ones need for special variables in Solver app; equation Library and etc.

#cas
dumber() //creating 10 dummy variables of f and vnvn
BEGIN
local k, ss;
FOR k FROM 1 TO 10 DO
ss:=left(STRING(k),10);
expr("f" +ss +":=" +0); //dummy f1,f2....f10
expr("v" +ss +v + ss +":=" +0); //dummy v1v1, v2v2....v10v10
END;
END;
#end
now I have all these dynamic variables....
efficient way to delete them or purge them when not needed....help?? efficient app function.
example....
if I do create say v1...v10 for 10 node circuit with their calculated values assigned. and also their corresponding potential differences say v1v2 ,v2v3......assigned.
how do I delete/purge all these variable(s) efficiently for my next circuit run. cos this time the circuit has only 5 nodes.
(11-21-2016 11:31 PM)toshk Wrote: [ -> ]now I have all these dynamic variables....
efficient way to delete them or purge them when not needed....help?? efficient app function.
Have you tried using the same way as for their creation?

Code:
#cas
dumberp() //purging 10 dummy variables of f and vnvn
BEGIN
local k, ss;
FOR k FROM 1 TO 10 DO
ss:=left(STRING(k),10); 
expr("purge(f" +ss +")"); //purge dummy f1,f2....f10
expr("purge(v" +ss +v + ss +")"); //purge dummy v1v1, v2v2....v10v10
END;
END;
#end
]
(11-22-2016 12:04 AM)Didier Lachieze Wrote: [ -> ]
(11-21-2016 11:31 PM)toshk Wrote: [ -> ]now I have all these dynamic variables....
efficient way to delete them or purge them when not needed....help?? efficient app function.
Have you tried using the same way as for their creation?

Code:
#cas
dumberp() //purging 10 dummy variables of f and vnvn
BEGIN
local k, ss;
FOR k FROM 1 TO 10 DO
ss:=left(STRING(k),10); 
expr("purge(f" +ss +")"); //purge dummy f1,f2....f10
expr("purge(v" +ss +v + ss +")"); //purge dummy v1v1, v2v2....v10v10
END;
END;
#end
]
....it seems to dump [DOM_SYMBOLIC] in all the variables.
When I execute dumber in Home it creates the CAS variables f1..f10, v1v1..v10v10.
Then if I execute dumberp in Home, it purges all these CAS variables.
(11-22-2016 04:50 PM)Didier Lachieze Wrote: [ -> ]When I execute dumber in Home it creates the CAS variables f1..f10, v1v1..v10v10.
Then if I execute dumberp in Home, it purges all these CAS variables.
in Home dumberp() is seems to delete the variable(s) completely....that's great! but with program error.
in Home dumber() works too ...but with the same program error too.
(11-22-2016 12:04 AM)Didier Lachieze Wrote: [ -> ]expr("purge(f" +ss +")"); //purge dummy f1,f2....f10
Nice to see what expr can do!
Reference URL's