solving unknown variables in matrices

52 次查看(过去 30 天)
So for un I've got to solve 3 variables from the equation y = k*x^2 + l*x + m, given are points P(-2, 4) Q(1,1) and R(2, -4). We are also instructed to use matrices.
I though a logical next step would be to make a matrix, matrix=[-2, 4;1, 1;2, -4]
From this you can make 3 linear equations, one for every row of the matrix. Is there a way to build and solve such an 'equation matrix' using Matlab? Or do I just have to do this by hand by treating it as a system of 3 coupled equations, which in this case isn't that difficult.
I've tried introducting the variables k, l and m into a matrix and making equations in there, but this hasnt worked.

采纳的回答

Lukas
Lukas 2019-1-4
You need to solve an linear optimization problem A*x = b. Each line is one of your points P,Q,R.
  • b is the solution vector and contains the y-variable of your three given points P,Q,R
b = [4 ; 1 ; -4]
  • x is the vector of (unknown) parameters, this means that
  • Each column of a corresponds to either x^0, x^1 or x^2 (for all points P,Q,R):
A = [1 -2 4;
1 1 1;
1 2 4]
The solution (where x = [m;l;k] ) is:
x = A\b
  4 个评论
Steven Lord
Steven Lord 2019-1-4
Because that's how the \ and / operators are defined. See the first section of this documentation page for more information.
John D'Errico
John D'Errico 2019-1-4
编辑:John D'Errico 2019-1-4
Personally, if I did not know the answer already, I might have guessed x=b/A would have been the logical notational choice, as that is what you would write if A were a scalar variable.
But I do understand how you might have been confused. And I'm not absolutely positive that there is a better way to remember it, except to know the answer, which you will do now. ;-)
We can just blame it on Cleve of course, but I have found Cleve to know what he is doing. Anyway, what does the syntax B/A mean? If we read the help for (forward) slash, we find it solves this problem:
/ Slash or right division.
B/A is the matrix division of A into B, which is roughly the
same as B*INV(A) , except it is computed in a different way.
Thus x=B/A solves the problem
x*A = B
for a square matrix A. If A is non-square, then it solves the problem in a least squares sense.
Ok, so B/A is not available, since it already has a logical definition. So long ago, in a galaxy far, far away, Cleve defined backslash to work as it does. :)

请先登录,再进行评论。

更多回答(1 个)

Torsten
Torsten 2019-1-4
[4 -2 1; 1 1 1;4 2 1]*[k;l;m] = [4; 1; -4]

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

产品


版本

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by