HP Forums
Command for having a list of variables of an equation? - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: Command for having a list of variables of an equation? (/thread-4592.html)



Command for having a list of variables of an equation? - Giancarlo - 08-28-2015 07:44 PM

Hello,
Is there a Home or Cas command able to output the list of variables of a given equation?

Thank you very much,

Giancarlo


RE: Command for having a list of variables of an equation? - Joe Horn - 08-28-2015 08:10 PM

(08-28-2015 07:44 PM)Giancarlo Wrote:  Hello,
Is there a Home or Cas command able to output the list of variables of a given equation?

Thank you very much,

Giancarlo

The CAS command lname() is probably what you're looking for. If not, also look at algvar() and lvar().


RE: Command for having a list of variables of an equation? - Giancarlo - 08-29-2015 10:09 AM

Hello John,
Thank you very much for your prompt answer. Unfortunately this is not what i am looking for. These CAS commands return only the list of lower case variables and only the one from a to z.

In a formula like: Surf = ((B1 + B2) * h)/2 i would like to have a list or a vector of variables like that including 'Surf', 'B1', 'B2' and h.

I know that i could use 's' for 'Surf', 'b' for 'B1' but this is not the point. If i have to think about an equation and i have to deal with a change of variable names, this implies an additional mental effort to me. I did it for the calculation of the inertia moment for generic shapes and believes me that it has been a nightmare to visually detect the errors.

What i am trying to do now is to adapt my old equation library dealing with the new and very powerful HVars and DelHVars commands to create variables in HOME, store an Eq, Solve it and then removes the variables.

One aspect that i discovered last night was the HVars command in the format HVars ("name", 2). This command returns the list of variables included in the 'name' variable if 'name' is a function. The issue again is that (i think) I cannot store a function without defining (STOring) each individual variable in advance.

At the moment my only solution for shaping my personal Eqlibrary is to ask to the user: the equation, the equation name and the list of variables. In this way i can create all the variables before storing the EQuation, solve the equation for any of its variables and then ask the user if he/she wants to delete the variables.

I hope someone can have another solution thinking out of the box,

Thanks

Giancarlo


RE: Command for having a list of variables of an equation? - parisse - 08-29-2015 12:59 PM

I don't understand the problem: lname(Surf = ((B1 + B2) * h)/2) returns [Surf, B1, B2, h]


RE: Command for having a list of variables of an equation? - DrD - 08-29-2015 02:05 PM

As a CAS command, it works in HOME also, note the quote:

[HOME]
lname("Surf = ((B1 + B2) * h)/2") ==> [Surf B1 B2 h]

-Dale-


RE: Command for having a list of variables of an equation? - Giancarlo - 08-29-2015 06:56 PM

Hello Bernard and Dale,
Unfortunately this doesn't work for me. If i run
[HOME]
CAS.lname (V=R×I0) ==> [ ].
CAS.lname ("V=R×I0") ==> [ ].
lname (V=R×I0) ==> [ ].
lname ("V=R×I0") ==> [ ].

Am i doing something wrong?

I am running os 8151 with cas 1.1.2-11.

Merci/Thanks

Giancarlo


RE: Command for having a list of variables of an equation? - DrD - 08-29-2015 07:20 PM

It's best not to use reserved variables (like R). For example if your expression was:

lname("V=Radius*I0") ==> [Radius I0]
or
lname("V=r*I0") ==> [r I0]

For reasons best explained by others, reserved variables are "special." <G>

-Dale-


RE: Command for having a list of variables of an equation? - Giancarlo - 08-29-2015 07:37 PM

Hello Dale,
I know that reserved variables A...Z are special. This is the reason why i put in the formula V=R×I0 where I0 is a capitol 'i' with a zero '0'. The 'I0' is not a reserved variable (A...Z).

With the command: lname ( V = R × I0 )
I was expecting [ V R I0] or [ I0] for the reason above regarding reserved variables.

The issue is that i only receive [ ] as answer.

Is that normal?

Giancarlo


RE: Command for having a list of variables of an equation? - Arno K - 08-29-2015 08:33 PM

(08-29-2015 07:37 PM)Giancarlo Wrote:  Hello Dale,
I know that reserved variables A...Z are special. This is the reason why i put in the formula V=R×I0 where I0 is a capitol 'i' with a zero '0'. The 'I0' is not a reserved variable (A...Z).

With the command: lname ( V = R × I0 )
I was expecting [ V R I0] or [ I0] for the reason above regarding reserved variables.

The issue is that i only receive [ ] as answer.

Is that normal?

Giancarlo

That is an issue discussed otherwhere on this forum, in CAS you must add quotes to the formula ie lname('R=V*I0'), that provides [R V I0], lname(Quote(R=V*I0)) again yields an empty list. So it seems to be difficult to be used in a program.
Arno


RE: Command for having a list of variables of an equation? - Giancarlo - 08-29-2015 08:39 PM

Hello,
I start seeing the point. Some variable names are not detected by the lname parser.
V1 is not detected, Vol is detected
R1 is not detected fR is detected
I0 is not detected Il is detected

Which is the rule?

Thanks

Giancarlo


RE: Command for having a list of variables of an equation? - Arno K - 08-29-2015 09:24 PM

You should get you a list of system-variables V1 is used in Advanced Graphing, R1 in Polar, I don't know why IO does not work. This list was made by Joe Horn, you can get it from here.
Arno


RE: Command for having a list of variables of an equation? - parisse - 08-30-2015 06:32 AM

If you are using HOME variables, they are replaced by their values during evaluation step, if the value is 0 then R*I0 cancels in your equation.


RE: Command for having a list of variables of an equation? - Marcus von Cube - 08-30-2015 11:58 AM

(08-30-2015 06:32 AM)parisse Wrote:  If you are using HOME variables, they are replaced by their values during evaluation step, if the value is 0 then R*I0 cancels in your equation.

I think it would help if the CAS completely ignored Home variables, except when they are qualified with "Home." or "Appname.". This way, everything from Home is still available on request but never comes in the way when not desired. For compatibility reasons, a user selectable CAS open "Require Home objects to be fully qualified" should be implemented.


RE: Command for having a list of variables of an equation? - Giancarlo - 08-30-2015 02:21 PM

Hello,
I start seeing the point. Some variable names are not detected by the lname parser.
V1 is not detected, Vol is detected
R1 is not detected fR is detected
I0 is not detected Il is detected

Which is the rule?

Thanks

Giancarlo


RE: Command for having a list of variables of an equation? - parisse - 08-30-2015 05:16 PM

As already explained, HOME variables are evaluated inside the equation argument of lname, that's why you won't see them (unless you quote the equation).