Post Reply 
Interesting question in the HP forums
09-10-2018, 05:58 AM
Post: #1
Interesting question in the HP forums
Hello,

Someone posted an interesting question in the HP powered Prime newsgroup..

https://h30434.www3.hp.com/t5/Calculator...-p/6821845

Basically, he wants to make a spreadsheet to solve 3*3 linear systems (like the lin solve app)..

Here is what I came up with... Does anyone have any better idea?



Althrough they are other ways to do it (for example with an app program)... Here is one sollution.


It is kind of kludgy due to some idiosyncraties of the spreadsheet, but it works..


Assume that you enter the system in A1:C4, enter, for A5, the following formula:

=M3:=((M2:=A1:C3)^(-1)*(M1:=D1Big Grin3))


Then, enter for A6 to C6: =M3(1), =M3(2) and =M3(3)


Here is why/how it works.

On the mathematic sides of thing, it works because if you put your system in a 3*3 matrix (M) form with the right side of the ax+by+cz=d equations in a vector (V), M^-1*V returns a vector which are the values for x, y and z... But I assume that you knew that.


A1:C3 will return a list of list which correspond to the "system" part of things. The problem is transforming it into a matrix. the cas list2mat can do this, BUT the cas can not extract values from the spreadsheet in the A1:C3 form as it does not know how to handle the ":" charater :-(

Hence the trick of storing the list of list into the M1 global variable. Since M1 is a matrix, the store operation will internally convert the list of list into a matrix and RETURN said matrix. Causing the transformation of the list of list into a matric.

We do the same for D1Big Grin3 (vector) and M2. We can now easely do the math...


Now the next step is the extraction of the 3 components of the responce.

Normally var(n), when var is a composit (list or matrix) gives access to the various elements...

Problem is that in the spreadsheet, call(n) gives access to the cell meta data (value, equation, format...).

Which is why the equation in A5 has the M3:= store. This make sure that the result vector is stored in M3 and allows the A6, B6 and C6 to access the nth elements of the result...


As as I said, kludgy, but works...


Cyrille

Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP.
Find all posts by this user
Quote this message in a reply
09-10-2018, 08:22 AM (This post was last modified: 09-10-2018 11:39 AM by Didier Lachieze.)
Post: #2
RE: Interesting question in the HP forums
Hi Cyrille,

I've tested it with the following system:

x+4*y+7*z = 10
-2*x+5*y+8*z = 11
3*x+6*y+9*z = 12

linsolve returns: [0,-1,2]

but your proposed solution returns: [-4.5, 0, 4.8333333...]

I think that you need to transpose M2 to make it work, and modify the formula in A5 to:

Code:
=M3:=((M2:=TRN(M2:=A1:C3))^(-1)*(M1:=D1:D3))


Here is an even more kludgy solution but which doesn't use the global variables M1, M2 or M3:

in A5 enter the formula:

Code:
=MAKEMAT(EXPR(CHAR(64+J)+I),3,3)^(-1)*MAKEMAT(EXPR("D"+I),3,1)

in A6 to C6 enter: =head(row(A5,0)), =head(row(A5,1)), =head(row(A5,2))

   

EDIT: here is another formula for A5 without using M1, M2 or M3 and avoiding the issue with CAS not recognizing the : in A1:C3

Code:
=TRN(list2mat(EXPR("A1:C3")))^(-1)*list2mat(EXPR("D1:D3"),1)

EDIT2: you can also replace the formula in A6 .. C6 by:

Code:
=row(A5,[0,0]), =row(A5,[1,0]), =row(A5,[2,0])
Find all posts by this user
Quote this message in a reply
09-11-2018, 04:59 AM
Post: #3
RE: Interesting question in the HP forums
Hello,

Nice solutions!

And congratulation on your 1000'd post!

Cyrille

Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP.
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)