# Something is wrong with my Matlab

25 views (last 30 days)
Juan Pablo Arrieta on 24 Sep 2020 at 15:44
Commented: Steven Lord on 24 Sep 2020 at 19:21
Hi, today I saw a challenge on internet, so I decided to solve it using math and Matlab to check if I was right.
It was about a 3x3 system of equations.
The equation was:
A = [x x x; x y y; y -2z]
b = [60 30 3]'
And this is what I used.
A = [1 1 1; 1 1 1; 0 1 -2]
b = [60 30 3]'
When I found out the values of x, y and z, the values were: x = 20, y = 5 and z = 1.
But, on Matlab, they showed me the values for x = 16.28, y = 20 and z = 8.5.
I used the "A\b" command and after I used the "pinv(A)*b" command.
What I did wrong? Can you help me with that?

Steven Lord on 24 Sep 2020 at 15:59
A = [x x x; x y y; y -2z]
b = [60 30 3]'
I suspect this is supposed to represent the equations 3*x = 60, x+2*y = 30, y-2*z = 3. That's not how I would have written them, but the question you're asking is about how to write them.
A = [1 1 1; 1 1 1; 0 1 -2]
b = [60 30 3]'
Those two matrices represent the equations x+y+z = 60, x+y+z = 30, y-2*z = 3. Those don't match the equations from the original problem, and the first two equations aren't consistent. How can the sum of x, y, and z simultaneously be equal to 60 and equal to 30?
The first element of the first row of your A should be the coefficient of the first variable in the first equation.
The second element of the first row of your A should be the coefficient of the second variable in the first equation.
The first element of the third row of your A should be the coefficient of the first variable in the third equation.
Can you translate the original equations into A using this pattern?

Juan Pablo Arrieta on 24 Sep 2020 at 16:58
I did it and I solve it.
The only thing I needed to do was replace A like this:
A = [3 0 0; 1 2 0; 0 1 -2]
Because "x + x + x" is "3*x" and the rest of the coefficients were 0.
The other equation "x + y + y" is "x + 2*y" and the other coefficient is 0.
The last one its okay.
The results were what I wrote at the beginning.
x = 20
y = 5
z = 1
Thank you very much! You helped me a lot!
And I apologize if my english isn't as good as a native speaker.
Steven Lord on 24 Sep 2020 at 19:21
You're welcome! And your English was good, I could understand what you said without a problem.
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}