Author Topic: Getting rid of fractions in matrices  (Read 1092 times)

0 Members and 1 Guest are viewing this topic.

Online MathWizardTopic starter

  • Super Contributor
  • ***
  • Posts: 1378
  • Country: ca
Getting rid of fractions in matrices
« on: October 23, 2021, 03:38:08 pm »
I was doing a node voltage problem and when I used Cramer's rule to get the answer, it's not matching the answer , or my calculator, what rule or math am missing or mixing up ?. I did linear algebra years ago, but I screw up node/mesh analysis too often with silly mistakes, I better review it more for AC analysis.

Then I have this problem, this matrix is from the example
Yv=i

0.75 -0.5 0 = 7
-0.5 4/3 -1/3 = -4
0 -1/3 5/6 = 7

If I plug that into my calc, I get V=(12 4 10)

I found detY=13/24, (and the calc agrees), and for Cramer's rule, the det of the 3 other matrices is
16/3
1/3
65/12

so then each of those divided by detY is
V1=128/13
V2=8/13
V3=10

well thats not (12 4 10)

But also in the example they go ahead and get rid of the fractions in Y, by multiplying (row 1)x4, (row2)x6 , (row3)x6, and the same on the output, giving
3 -2 0 = 28
-3 8 -2 = -24
0 -2 5 = 28

and plugging that into the calc gives V=(12 4 10). I don't remember how that works out the same, since I got the wrong answer for the other.

I haven't taken the inverse of either matrix to see that way, but why is Cramer's rule not working or what am I doing wrong ?
« Last Edit: October 23, 2021, 03:40:25 pm by MathWizard »
 

Offline electr_peter

  • Supporter
  • ****
  • Posts: 1300
  • Country: lt
Re: Getting rid of fractions in matrices
« Reply #1 on: October 23, 2021, 04:10:53 pm »
I looked through calculations.
I found detY=13/24, (and the calc agrees), and for Cramer's rule, the det of the 3 other matrices is
16/3
1/3

65/12
It is actually
13/2
13/6

65/12
which gives 12/4/10 as a result. Determinant values were incorrect.

Quote
...
But also in the example they go ahead and get rid of the fractions in Y, by multiplying (row 1)x4, (row2)x6 , (row3)x6, and the same on the output, giving
3 -2 0 = 28
-3 8 -2 = -24
0 -2 5 = 28
It should be
3 -2 0 = 28
-3 8 -2 = -24
0 -2 5 = 42
After some linear manipulations you will get the same answer.

For simple linear equations I would go for algebraic manipulations (multiplication and summation of lines) or straight to inverse matrix calculation. I don't think Cramer's rule is beneficial in such cases as it still requires significant effort (more determinants are needed) and you want full answer for all variables (not just one).
« Last Edit: October 23, 2021, 04:13:41 pm by electr_peter »
 
The following users thanked this post: MathWizard

Online MathWizardTopic starter

  • Super Contributor
  • ***
  • Posts: 1378
  • Country: ca
Re: Getting rid of fractions in matrices
« Reply #2 on: October 23, 2021, 04:17:00 pm »
nvm seems I did just waste time and make a stupid mistakes, if I had these on a test, I better let the calculator do the math, I'll be mixing up too many numbers

I looked at it a few times, but each time I missed my mistakes.
« Last Edit: October 23, 2021, 04:19:41 pm by MathWizard »
 

Offline Nominal Animal

  • Super Contributor
  • ***
  • Posts: 6173
  • Country: fi
    • My home page and email address
Re: Getting rid of fractions in matrices
« Reply #3 on: October 24, 2021, 12:26:39 pm »
In case you want to pretty-print your matrices, you can either use [tt]...[/tt] and Unicode characters (Bracket Pieces from the Unicode Miscellaneous Technical set, U+239B to U+23AE:
    ⎡  0.75  -0.50  0.0 ⎤ ⎡ a ⎤   ⎡  7 ⎤
    ⎢ -0.5    4/3  -1/3 ⎥ ⎢ b ⎥ = ⎢ -4 ⎥
    ⎣  0     -1/3   5/6 ⎦ ⎣ c ⎦   ⎣  7 ⎦

Or, you can use MathJax.  Using
    $$ \left [ \begin{matrix}
    0.75 & -0.50 & 0.0 \\
    -0.5 & 4/3 & -1/3 \\
    0 & -1/3 & 5/6 \\
    \end{matrix} \right ] \left [ \begin{matrix}
    a \\ b \\ c \\
    \end{matrix} \right ] = \left [ \begin{matrix}
    7 \\ -4 \\ 7 \\
    \end{matrix} \right ] $$
you get $$ \left [ \begin{matrix}
0.75 & -0.50 & 0.0 \\
-0.5 & 4/3 & -1/3 \\
0 & -1/3 & 5/6 \\
\end{matrix} \right ] \left [ \begin{matrix}
a \\ b \\ c \\
\end{matrix} \right ] = \left [ \begin{matrix}
7 \\ -4 \\ 7 \\
\end{matrix} \right ]$$
but unfortunately it does not show up correctly in preview, only when you post.  The MathJax Quick Reference at StackOverflow works here too, except that inline math expressions must be \$ ... \$ , a single $ does not suffice here.  Again, preview does not show the rendered version, you'll only see the result when posting.

I do like to recommend maxima (text-based) or wxMaxima (GUI version), both available for all OSes (Windows, Macs, Linux, source code for others), and is free of cost and licensed under the GPL.  The single-page manual can be found here.  With maxima:
    A : matrix([ 3/4, -1/2, 0], [ -1/2, 4/3, -1/3 ], [ 0, -1/3, 5/6 ]) $
    determinant(A);
shows the determinant of the matrix, 13/24. To solve A.x = y for column vector x, we construct column vector y,
    y : matrix([ 7 ], [ -4 ], [ 7 ]) $
and obtain the result via x = (A^^-1) . y,
    invert(A) . y;
which shows the result, x : matrix([ 12 ], [ 4 ], [10]) $.
(Maxima matrix functions are listed e.g. here.)
« Last Edit: October 24, 2021, 12:29:09 pm by Nominal Animal »
 

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3032
  • Country: us
Re: Getting rid of fractions in matrices
« Reply #4 on: October 24, 2021, 04:42:29 pm »
I found an online version of maxima here:

http://maxima.cesga.es/
 
The following users thanked this post: Nominal Animal

Online MathWizardTopic starter

  • Super Contributor
  • ***
  • Posts: 1378
  • Country: ca
Re: Getting rid of fractions in matrices
« Reply #5 on: October 26, 2021, 12:47:28 pm »
Yeah when doing these with complex numbers, my calculator won't (as far as I can tell) allow c#'s in matrices.

I have GNU Octave, I haven't used it ages, time to refresh my memory.
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9886
  • Country: us
Re: Getting rid of fractions in matrices
« Reply #6 on: October 26, 2021, 03:17:35 pm »
I like MATLAB (and Octave):

Code: [Select]
A = [ 0.75 -0.5    0;
     -0.5   4/3 -1/3;
      0.0  -1/3  5/6 ]
 
B = [ 7;
     -4;
      7 ]

Y = inv(A) * B

% add results to bottom of source code

% Y =
%    12.0000
%     4.0000
%    10.0000

It works in Octave even with the commented results at the end of the file.  No changes required!
« Last Edit: October 26, 2021, 03:30:56 pm by rstofer »
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9886
  • Country: us
Re: Getting rid of fractions in matrices
« Reply #7 on: October 26, 2021, 03:30:05 pm »
I found an online version of maxima here:

http://maxima.cesga.es/

The wxMaxima incantation (with GUI) is a terrific tool!  I like MATLAB a little better but wxMaxima rates right up there.

https://sourceforge.net/projects/wxmaxima/

I like to mess around with Simulink and these days I am playing with Deep Learning. MATLAB provides a toolbox for this kind of thing.  So I use MATLAB for just about everything.
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9886
  • Country: us
Re: Getting rid of fractions in matrices
« Reply #8 on: October 26, 2021, 04:51:44 pm »
As to mesh analysis with AC and complex numbers, here is an epic thread of Simon's from about 5 years ago.  There's a LOT of good information in this thread.  Lots of different tools used to come up with the same answer.

https://www.eevblog.com/forum/beginners/mesh-analysis/

I came up with a wxMaxima solution in Reply 149 & 150 - the last two replies.  There are other solutions...
« Last Edit: October 26, 2021, 05:17:06 pm by rstofer »
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14306
  • Country: fr
Re: Getting rid of fractions in matrices
« Reply #9 on: October 26, 2021, 05:00:09 pm »
I found an online version of maxima here:

http://maxima.cesga.es/

The wxMaxima incantation (with GUI) is a terrific tool!  I like MATLAB a little better but wxMaxima rates right up there.

But Maxima does symbolic algebra. Matlab does not! (Well, I don't think it does anyway.)
A closer open-source tool to Matlab is Scilab.
Maxima is great for symbolic computation.
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9886
  • Country: us
Re: Getting rid of fractions in matrices
« Reply #10 on: October 26, 2021, 05:27:23 pm »
I found an online version of maxima here:

http://maxima.cesga.es/

The wxMaxima incantation (with GUI) is a terrific tool!  I like MATLAB a little better but wxMaxima rates right up there.

But Maxima does symbolic algebra. Matlab does not! (Well, I don't think it does anyway.)
A closer open-source tool to Matlab is Scilab.
Maxima is great for symbolic computation.

There's an add-on toolbox for that kind of thing:

https://www.mathworks.com/help/symbolic/performing-symbolic-computations.html

Octave is very close to the basic (add-on free) MATLAB.  They're not always syntactically identical and Octave probably has the better syntax options (like embedded underscores in numeric constants like 1_250_000) and while Octave will accept MATLAB '%' as the beginning of a comment, MATLAB will not accept Octave's '#'.

Maxima seems to prefer symbolic results.  I usually want a number...
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9886
  • Country: us
Re: Getting rid of fractions in matrices
« Reply #11 on: October 26, 2021, 05:31:36 pm »
At my grandson's university, incoming STEM students are required to take a course in MATLAB as they will be using it extensively for the next 4 to 5 years!  Of course students get the program FREE.

 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14306
  • Country: fr
Re: Getting rid of fractions in matrices
« Reply #12 on: October 26, 2021, 05:44:09 pm »
Have you tried Scilab? https://www.scilab.org/
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9886
  • Country: us
Re: Getting rid of fractions in matrices
« Reply #13 on: October 26, 2021, 06:14:10 pm »
Have you tried Scilab? https://www.scilab.org/

I think I installed it on a machine some years back but I don't recall spending any time with it.  It is interesting to see that portions of it are written in Fortran - my favorite language.  I'm guessing it is the linear algebra package BLAS...

I don't use MATLAB for 'numbers' all that much..  I use it for Simulink and now the Deep Learning package.  Numbers are a side issue at the moment.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf