I want to solve the following system with MSLV and enter on the stack:
['X+Y=1' 'Z+R=1' 'X+Z+Y+R=2']
['X' 'Y' 'Z' 'R']
[0. 0. 0. 0.]
And go to the MSLV application in the NUM.SLV menu on the 49g+.
However, the hp49g+ complains:
"MSLV Error:
Bad Argument
Value"
Why/What is that? If I use only 2 equations and 2 variables (X and Y),
it works. I don't care whether the system above has a solution or not,
it's just a sample case for me to get to know the operating of the MSLV
command. Can it work with 2 equations only?
2) MSLV seems to work pretty slowly (when it works at all). Are there
faster solvers for large systems of non-linear equations for the hp49g+
available? (I know that the above system is linear).
Thank you very much for your time,
Michael Kuyumcu
You have in your example, only 3 equations but 4 variables. Furthermore,
only two of your equations are "independent", as the last is merely the
sum of the first two. There is no way that one can solve for all
variables. Given X or Y one can find the other and given one of Z or R
one can find the other, but nothing else.
The calculator is quite right to object.
it seems you have 3 equations and 4 unknowns, therefore
you can not find a numerical solution. MSLV is a numeric
solver using Newton method with prefactor.
> If I use only 2 equations and 2 variables (X and Y),
> it works. I don't care whether the system above has a solution or not,
> it's just a sample case for me to get to know the operating of the MSLV
> command. Can it work with 2 equations only?
>
> 2) MSLV seems to work pretty slowly (when it works at all). Are there
> faster solvers for large systems of non-linear equations for the hp49g+
> available? (I know that the above system is linear).
>
For polynomial systems, you can try SOLVE which will call
Groebner basis algorithm, but don't expect too much on
a calculator...
Regards, and again, thanks for responding
Michael Kuyumcu
I just found a fast efficient solver application on hpcalc.org that
handles all imaginable cases, under- and over-determined. It seems it
also uses the Newton method. It works like a charm (solving for 49
unknows in a couple of seconds), the only problem is that it creates a
variable in the current directory for each of the unknows, containing
the calculated approximate or exact value while I rather need all these
values as a list.
Do you know of any method to assemble the contents of a directory (the
names of the stored variables stored there) in a list? I am new to the
hp, and just found that the DIR command does (with no arguments) not do
what I intended.
Thank you very much!
Regards,
Michael Kuyumcu
Hello,
VARS will return a list with all the variable names in the directory. If
you only want the names of vars with real numbers only, use this:
<< VARS DUP 1 <<RCL TYPE>> DOLIST
{} SWAP DUP SIZE 1 DUP ROT
FOR j GETI 0 ==
<< ROT 4 PICK j GET + UNROT >>
IFT
NEXT DROP2 NIP
>>
which should leave a list with all the names in the current directory
which contain real numbers (this is checked by comparing their TYPE to
0, which is the type for reals) and nothing else.
Warning: I have not checked this (I ran it once on my calculator);
furhtermore, I have not written a single program for about a year, so
this is possibly buggy and certainly kludgy.
If someone could streamline it, I'd appreciate it.
Somewhat less idiotic:
<< VARS LIST-> {} 1 ROT
START SWAP DUP RCL TYPE 0 ==
<< + >>
<< DROP >> IFTE
NEXT
>>
Warning: I have not tested this at all, but it should work.
Ah, but where's the fun in that? :)
Thanks for the tip...
CR wrote:
> "acl" wrote:
> >
> > << VARS DUP 1 <<RCL TYPE>> DOLIST
> > {} SWAP DUP SIZE 1 DUP ROT
> > FOR j GETI 0 ==
> > << ROT 4 PICK j GET + UNROT >>
> > IFT
> > NEXT DROP2 NIP
> > >>
> >
> > which should leave a list with all the names in the current directory
> > which contain real numbers (this is checked by comparing their TYPE to 0,
> > which is the type for reals) and nothing else.
> snipped
> > If someone could streamline it, I'd appreciate it.
>
> Try also 0. TVARS for vars containing reals.
Or { 0 28 } TVARS for vars containing real or integer, etc.
[r->] [OFF]
> I want to solve the following system with MSLV and enter on the stack:
>
> ['X+Y=1' 'Z+R=1' 'X+Z+Y+R=2']
> ['X' 'Y' 'Z' 'R']
> [0. 0. 0. 0.]
>
> And go to the MSLV application in the NUM.SLV menu on the 49g+.
>
> However, the hp49g+ complains: "MSLV Error: Bad Argument Value"
On Mon, 07 Aug 2006 02:45:54 -0500, Michael Kuyumcu wrote:
> Thanks, I now see what the hp is trying to communicate. Anyhow, I feel
> that the algorithms used by the hp should be able to deal with such
> cases, over-determined as well as under-determined, and interdependent
> equations. The hp could and should have eliminated the dependent
> equation and solved the ones remaining. Providing one solution of the
> many available would then be a first step, and giving parameterized
> solutions an even better one. The system I entered does have a
> solution, and the fact that the hp can't find any is quite
> disconcerting. I just found on hpcalc.org a solver that handles all the
> mentioned cases - and much faster than the limited (I'd almost like to
> call it dysfunctional for many real-world cases) in-built program. It's
> only around 3000 bytes, so that could and should have been squeezed
> into the ROM.
It's already in the ROM! (and has been there for 13 years!)
Forget the 49G[+]/50G; try the old-fashioned 48G[X] way:
Think A*X=B and put on the stack:
:B: [ 1. 1. 2. ]
:A: [ [1. 1. 0. 0.] [0. 0. 1. 1.] [1. 1. 1. 1.] ]
Now type LSQ, see answer:
[ .5 .5 .5 .5 ]
The "Solve linear system" built-in application
will give the same result.
LSQ for an under-determined system
minimizes the solutions' Frobenius/Euclidean norm
http://mathworld.wolfram.com/FrobeniusNorm.html
For an over-determined system,
LSQ minimizes the norm of the residual A*X-B
[r->] [OFF]
> I want to solve the following system with MSLV and enter on the stack:
>
> ['X+Y=1' 'Z+R=1' 'X+Z+Y+R=2']
> ['X' 'Y' 'Z' 'R']
Which one of the infinite number of solutions do you want?
Regards
Steen
Regards,
Michael Kuyumcu
On Tue, 08 Aug 2006 12:17:28 -0500, Michael Kuyumcu wrote:
> One would be enough. Am I asking too much? Just one lousy little
> solution out of the infinite many. The hp cannot even give you that.
Tried LSQ or "Solve linear sys" yet? (previous post this morning).
All HP48G[X]/HP49/HP50 have it built-in.
[r->] [OFF]
thanks for the tip. Actually, I am trying to solve a system of
non-linear equations. I have several dozens of equations of the type
A11*A12*A21*A22=0, where A11, A12, etc. are the unknows. Moreover, I
have only 49 vars but 449 equations (441 of the mentioned non-linear
type and additional 8 purely linear equations). I just posted the
example since I wondered if maybe MSLV couldn't handle non-linear
systems, so I tried a linear one. Do you think LSQ will handle
non-linear systems, too?
Apart from this, on hpcalc.org I found the program solvesys which
handles all cases (regular, over- and underdetermined) quite nicely and
quickly. It's quite comfortable, too, and I am very satisfied with it.
I will now try and figure out the algorithms behind the software (the
program documentation mentioned two books) and try to improve the
program. I would, for instance, like to program to be able to deal with
bounded systems of nonlinear equations as well, meaning: having lower
and upper boundaries for the unknows, like 0 = A11 = 1. That would
help my particular problem a lot.
Again, thank you for your help!
Regards,
Michael Kuyumcu
> Do you think LSQ will handle non-linear systems, too?
No.
> Apart from this, on hpcalc.org I found the program solvesys
> [well-recommended program by Sune Bredahl, in use long time for 48/49]
> which handles all cases (regular, over- and underdetermined)
> quite nicely and quickly. It's quite comfortable, too,
> and I am very satisfied with it.
> I will now try and figure out the algorithms behind the software (the
> program documentation mentioned two books) and try to improve the
> program. I would, for instance, like to program to be able to deal with
> bounded systems of nonlinear equations as well, meaning: having lower
> and upper boundaries for the unknowns, like 0 < A11 < 1. That would
> help my particular problem a lot.
If you could just generalize that to have bounded functions
of several variables, and if you could select that solution
which simultaneously maximizes or minimizes any non-linear function
of all the variables, then I believe this would be
yet another great feature ;-)
[r->] [OFF]
Regards,
Michael Kuyumcu
> That sounds quite sophisticated.
I was just trying to have you take on the task of making
a completely generalized "non-linear programming" package
to run on a calculator :)
When I was employed at a major oil company some decades ago,
they dedicated two room-sized state-of the art high-end IBM mainframes
to do just "linear programming" to optimize all their refineries :)
[r->] [OFF]