Post Reply 
Some issues solving linear equation
06-22-2018, 01:06 PM (This post was last modified: 06-22-2018 01:09 PM by sasa.)
Post: #1
Some issues solving linear equation
While testing Emu48 for another issue, testing certain samples shows some minor issues...

Solving linear equation on 48GX (I'm unaware of ROM version, it is found at hpcalc.org) shows following:

x + y + 2z = -2
3x - y + 14z = 6
x + 2y = -5

x = -.904761904762
y = -2.04761904762
z = .47619047619

This is only one of solution, as this system have infinite number of solutions, however there is no further notice from the calculator about. The solution actually is in form:
x = -4n + 1
y = 2n - 3
z = n

The following synthetic example is much more obvious, the system have no solution:
x - 5y + 3z = -8
0x + 2y + 1z = 3
0x + 0y + 0z = 7

However, emulator returns:
x = -.150793650794
y = 1.5374603175
z = -6.34920634921E-2

This may indicate the method used to solve linear equation (probably inversion matrix). With Gauss-Jordan method of elimination, solution or at least note about it is straightforward.

Perhaps this as well is noted in the calculator's documentation. However, I'm interested what is result of more recent calculators on these synthetic examples, for instance on Prime.
Find all posts by this user
Quote this message in a reply
06-22-2018, 04:34 PM
Post: #2
RE: Some issues solving linear equation
(06-22-2018 01:06 PM)sasa Wrote:  x + y + 2z = -2
3x - y + 14z = 6
x + 2y = -5

HP 39gs says infinite solutions.

Quote:x - 5y + 3z = -8
0x + 2y + 1z = 3
0x + 0y + 0z = 7

HP 39gs says no solutions.

— Ian Abbott
Find all posts by this user
Quote this message in a reply
06-22-2018, 06:31 PM (This post was last modified: 06-22-2018 06:32 PM by Dieter.)
Post: #3
RE: Some issues solving linear equation
First of all I have to say that I don't know anything about the HP48 series and its mathematical algorithms. But there are is something that makes me wonder if it could be a clue for finding the solution here.

(06-22-2018 01:06 PM)sasa Wrote:  x + y + 2z = -2
3x - y + 14z = 6
x + 2y = -5

x = -.904761904762
y = -2.04761904762
z = .47619047619

This is only one of solution, as this system have infinite number of solutions, however there is no further notice from the calculator about. The solution actually is in form:
x = -4n + 1
y = 2n - 3
z = n

And that's also what the emulator returned here. In this case for n = 10/21.

May it be possible that you have this value (0,47619...) stored somewhere in a variable so that the emulator evaluates the given general solution for the case where the parameter (you named it n) has this special value? Have you tried clearing all variables?

(06-22-2018 01:06 PM)sasa Wrote:  The following synthetic example is much more obvious, the system have no solution:
x - 5y + 3z = -8
0x + 2y + 1z = 3
0x + 0y + 0z = 7

However, emulator returns:
x = -.150793650794
y = 1.5374603175
z = -6.34920634921E-2

Again the factor 10/21 shows up. Here z = –2/15 · 10/21. Or –4/63 if you prefer.

That's why I suspect that somewhere a variable with such a value may be stored and the calculator / emulator includes this value while generating the solution.

Just an idea.

Dieter
Find all posts by this user
Quote this message in a reply
06-23-2018, 05:53 AM (This post was last modified: 06-23-2018 06:09 AM by sasa.)
Post: #4
RE: Some issues solving linear equation
Thank you to both.

It seems then this is fixed in recent calculators or used different method for solving...
To be more clear, matrix in both systems is singular, therefore inverse matrix is not possible to create.

However, without looking in the algorithm, it is unknown why such results are shown, nor why noted factor is used to show these results in the second example, even memory was reset, as well reopen emulator without previously saved data.
Find all posts by this user
Quote this message in a reply
06-23-2018, 06:25 AM
Post: #5
RE: Some issues solving linear equation
(06-22-2018 01:06 PM)sasa Wrote:  I'm interested what is result of more recent calculators on these synthetic examples, for instance on Prime.

On the Prime in CAS mode :
linsolve([x+y+2*z=-2,3*x-y+14*z=6,x+2*y=-5],[x,y,z])
returns [-4*z+1,2*z-3,z]

linsolve([x-5*y+3*z=-8,0*x+2*y+z=3,0*x+0*y+0*z=7],[x,y,z])
returns: []
Find all posts by this user
Quote this message in a reply
06-23-2018, 09:05 AM (This post was last modified: 06-23-2018 09:10 AM by ijabbott.)
Post: #6
RE: Some issues solving linear equation
(06-22-2018 01:06 PM)sasa Wrote:  Solving linear equation on 48GX (I'm unaware of ROM version, it is found at hpcalc.org) shows following:

x + y + 2z = -2
3x - y + 14z = 6
x + 2y = -5

x = -.904761904762
y = -2.04761904762
z = .47619047619

This is only one of solution, as this system have infinite number of solutions, however there is no further notice from the calculator about. The solution actually is in form:
x = -4n + 1
y = 2n - 3
z = n

The "Solve lin sys..." app on the HP 50g produces the same solution.

However:
Code:
['X+Y+2*Z=-2','3*X-Y+14*Z=6','X+2*Y=-5']
['X','Y','Z']
LINSOLVE
produces:
Code:
{ [ 'X+Y+2*Z=-2' '3*X-Y+14·Z=6' 'X+2*Y=-5' ] [ 'X' 'Y' 'Z' ] }
:Specific: { 4 -4 0 4 2. }
[ 'X=1-4*Z' 'Y=-3--2*Z' ]

I don't know what the ":Specific:" line means. And that's a strange use of double negative in the solution!

Quote:The following synthetic example is much more obvious, the system have no solution:
x - 5y + 3z = -8
0x + 2y + 1z = 3
0x + 0y + 0z = 7

However, emulator returns:
x = -.150793650794
y = 1.5374603175
z = -6.34920634921E-2

Again, the "Solve lin sys..." app on the HP 50g produces the same result, but the LINSOLVE function produces:
Code:
{ [ 'X-5*Y+3*Z=-8' '0*X+2*Y+1*Z=3' '0*X+0*Y+0*Z=7' ] [ 'X' 'Y' 'Z' ] }
:Specific: { 14 14 0 7 2. 2 1. }
[ 'X=-(11*Z)/2' 'Y=-Z/2' '1=0' ]

— Ian Abbott
Find all posts by this user
Quote this message in a reply
06-23-2018, 10:20 AM
Post: #7
RE: Some issues solving linear equation
Look at page 18-12 of the HP 48G user's guide. For overdetermined systems the linear system solver will return the least-squares solution. For underdetermined systems it will return the minimum norm solution.

It won't warn the user so you have to check the system of equations before. I've always considered the HP 48 family of calculators a great supplement to their manuals.
Find all posts by this user
Quote this message in a reply
06-23-2018, 10:36 AM
Post: #8
RE: Some issues solving linear equation
(06-23-2018 06:25 AM)Didier Lachieze Wrote:  
(06-22-2018 01:06 PM)sasa Wrote:  I'm interested what is result of more recent calculators on these synthetic examples, for instance on Prime.

On the Prime in CAS mode :
linsolve([x+y+2*z=-2,3*x-y+14*z=6,x+2*y=-5],[x,y,z])
returns [-4*z+1,2*z-3,z]

linsolve([x-5*y+3*z=-8,0*x+2*y+z=3,0*x+0*y+0*z=7],[x,y,z])
returns: []

TI-Nspire CX CAS in Exact mode:

linSolve({x+y+2·z=−2,xy+14·z=6,x+2·y=−5},{x,y,z})
returns: { −(4·c1−1),2·c1−3,c1 }

linSolve({x−5·y+3·z=−8,0·x+2·y+z=3,0·x+0·y+0·z=7},{x,y,z})
gives: "Error: Argument Error"

— Ian Abbott
Find all posts by this user
Quote this message in a reply
06-23-2018, 12:10 PM
Post: #9
RE: Some issues solving linear equation
(06-22-2018 01:06 PM)sasa Wrote:  While testing Emu48 for another issue, testing certain samples shows some minor issues...

Solving linear equation on 48GX (I'm unaware of ROM version, it is found at hpcalc.org) shows following:

x + y + 2z = -2
3x - y + 14z = 6
x + 2y = -5

x = -.904761904762
y = -2.04761904762
z = .47619047619

This is only one of solution, as this system have infinite number of solutions, however there is no further notice from the calculator about. The solution actually is in form:
x = -4n + 1
y = 2n - 3
z = n

The following synthetic example is much more obvious, the system have no solution:
x - 5y + 3z = -8
0x + 2y + 1z = 3
0x + 0y + 0z = 7

However, emulator returns:
x = -.150793650794
y = 1.5374603175
z = -6.34920634921E-2

This may indicate the method used to solve linear equation (probably inversion matrix). With Gauss-Jordan method of elimination, solution or at least note about it is straightforward.

Perhaps this as well is noted in the calculator's documentation. However, I'm interested what is result of more recent calculators on these synthetic examples, for instance on Prime.

You are the master, the calculator is the servant. Give it weird questions and you'll get relevant answers. Do not expect 20 yo program to decipher everything for you, compare ability to read a map to satellite navigation of today. Calculators were tools, not artificial intelligence math tutors.

Regards,
Find all posts by this user
Quote this message in a reply
06-23-2018, 01:41 PM (This post was last modified: 06-23-2018 02:14 PM by sasa.)
Post: #10
RE: Some issues solving linear equation
(06-23-2018 12:10 PM)RMollov Wrote:  You are the master, the calculator is the servant. Give it weird questions and you'll get relevant answers. Do not expect 20 yo program to decipher everything for you, compare ability to read a map to satellite navigation of today. Calculators were tools, not artificial intelligence math tutors.

Thank you for pointing all that - that is exactly the point.

Since solving system of n linear equations with n unknowns is relatively simple for a silicon chip implementation and well established through the math and computer history, there is nothing complicated in performing exact solution with in exactly established steps, all in desired real time, even with very slow CPU. The limited factors are only ROM, RAM and proper speed of CPU.

It is not an issue to perform additionally preliminary check up to matrix rang 3 or 4, however for more than that may be a problem for a human. Such strange result from a calculator with relatively high performance comparing computational power of a human is not exactly what is expected.

A bit OT. As a senior programmer, I always find such limitations unjustified, more precisely I personally consider them more as trivial/minor bugs. I have actually performed many years ago my own 64-bit double precision floating point library (IEEE-754 compatible) made from ground in pure C++, able to calculate trig functions fast and accurate to the last bit of mantissa, as well able to do some geodetic and astronomical calculations as well in real-time, within plain 8-bit AVRs (16MHz max)...

Therefore, solving system of n linear equations with n unknowns (where n is limited by available RAM) which will show exact solution as modern CAS capable calculators offers, on such modest MCU is not nearly complicated task. However, all that is perhaps for another topic and different forum section...
Find all posts by this user
Quote this message in a reply
07-02-2018, 03:56 PM
Post: #11
RE: Some issues solving linear equation
After a bit more investigation, I have found that 48GX have RREF command, which is all necessary to show exact results in all upper examples. In that case, SOLVE function is not needed at for solving systems of linear equations.
Find all posts by this user
Quote this message in a reply
07-04-2018, 01:32 PM (This post was last modified: 07-04-2018 01:35 PM by damaltor.)
Post: #12
RE: Some issues solving linear equation
my 2 cents: the hp-15c returns
x=1
y=-3
z=0

and
x=-3,85e11
y=-3,5e10
z=7e10

and the coefficient c3 in the last line in front of the z was changed to 1e-10, which is probably a bug in the algorithm. i tried a second time, and got ERROR 0 (divide by zero), and i tried a third time, and received the same result as the first time.
Find all posts by this user
Quote this message in a reply
Post Reply 




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