Getting rid of fractions in matrices - Page 1
Forum section: electronics / projects

author: MathWizard
author_rank: Super Contributor
timestamp: October 23, 2021, 03:38:08 pm
content: 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 exampleYv=i0.75 -0.5 0 = 7-0.5 4/3 -1/3 = -40 -1/3 5/6 = 7If 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 is16/31/365/12so then each of those divided by detY isV1=128/13V2=8/13V3=10well 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, giving3 -2 0 = 28-3 8 -2 = -240 -2 5 = 28and 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 ?

author: electr_peter
author_rank: Unknown
timestamp: October 23, 2021, 04:10:53 pm
content: I looked through calculations.Quote from: MathWizard on October 23, 2021, 03:38:08 pmIt is actually13/213/665/12which gives 12/4/10 as a result. Determinant values were incorrect.QuoteIt should be3 -2 0 = 28-3 8 -2 = -240 -2 5 = 42After 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).

author: MathWizard
author_rank: Super Contributor
timestamp: October 23, 2021, 04:17:00 pm
content: 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 numbersI looked at it a few times, but each time I missed my mistakes.

author: Nominal Animal
author_rank: Super Contributor
timestamp: October 24, 2021, 12:26:39 pm
content: In case you want to pretty-print your matrices, you can either use...and Unicode characters (Bracket Pieces from theUnicode Miscellaneous Technicalset, 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. TheMathJax Quick Referenceat 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 recommendmaxima(text-based) orwxMaxima(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 foundhere. 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 solveA.x = yfor column vectorx, we construct column vectory,y : matrix([ 7 ], [ -4 ], [ 7 ]) $and obtain the result viax = (A^^-1) . y,invert(A) . y;which shows the result,x : matrix([ 12 ], [ 4 ], ) $.(Maxima matrix functions are listed e.g.here.)

author: ledtester
author_rank: Super Contributor
timestamp: October 24, 2021, 04:42:29 pm
content: I found an online version of maxima here:http://maxima.cesga.es/

author: MathWizard
author_rank: Super Contributor
timestamp: October 26, 2021, 12:47:28 pm
content: 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.

author: rstofer
author_rank: Super Contributor
timestamp: October 26, 2021, 03:17:35 pm
content: I like MATLAB (and Octave):Code: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.0000It works in Octave even with the commented results at the end of the file. No changes required!

author: rstofer
author_rank: Super Contributor
timestamp: October 26, 2021, 03:30:05 pm
content: Quote from: ledtester on October 24, 2021, 04:42:29 pmThe 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.

author: rstofer
author_rank: Super Contributor
timestamp: October 26, 2021, 04:51:44 pm
content: 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...

author: SiliconWizard
author_rank: Super Contributor
timestamp: October 26, 2021, 05:00:09 pm
content: Quote from: rstofer on October 26, 2021, 03:30:05 pmBut 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.

author: rstofer
author_rank: Super Contributor
timestamp: October 26, 2021, 05:27:23 pm
content: Quote from: SiliconWizard on October 26, 2021, 05:00:09 pmThere's an add-on toolbox for that kind of thing:https://www.mathworks.com/help/symbolic/performing-symbolic-computations.htmlOctave 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...

author: rstofer
author_rank: Super Contributor
timestamp: October 26, 2021, 05:31:36 pm
content: 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.

author: SiliconWizard
author_rank: Super Contributor
timestamp: October 26, 2021, 05:44:09 pm
content: Have you tried Scilab?https://www.scilab.org/

author: rstofer
author_rank: Super Contributor
timestamp: October 26, 2021, 06:14:10 pm
content: Quote from: SiliconWizard on October 26, 2021, 05:44:09 pmI 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.