Something is wrong with my Matlab
3 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
Steven Lord
2020-9-24
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?
2 个评论
Steven Lord
2020-9-24
You're welcome! And your English was good, I could understand what you said without a problem.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!