EEVblog Electronics Community Forum
Electronics => Projects, Designs, and Technical Stuff => Topic started by: MathWizard 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 ?
-
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.
...
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).
-
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.
-
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 (https://unicode-table.com/en/blocks/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 (https://math.meta.stackexchange.com/questions/5020/mathjax-basic-tutorial-and-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 (https://maxima.sourceforge.io/) (text-based) or wxMaxima (https://wxmaxima-developers.github.io/wxmaxima/download.html) (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 (https://maxima.sourceforge.io/docs/manual/maxima_singlepage.html). 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 (https://maxima.sourceforge.io/docs/manual/maxima_singlepage.html#Functions-and-Variables-for-Matrices-and-Linear-Algebra).)
-
I found an online version of maxima here:
http://maxima.cesga.es/ (http://maxima.cesga.es/)
-
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.
-
I like MATLAB (and Octave):
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!
-
I found an online version of maxima here:
http://maxima.cesga.es/ (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.
-
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/ (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...
-
I found an online version of maxima here:
http://maxima.cesga.es/ (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.
-
I found an online version of maxima here:
http://maxima.cesga.es/ (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 (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...
-
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.
-
Have you tried Scilab? https://www.scilab.org/ (https://www.scilab.org/)
-
Have you tried Scilab? https://www.scilab.org/ (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.