solving unknown variables in matrices

52 views (last 30 days)
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.

Accepted Answer

Lukas
Lukas on 4 Jan 2019
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 Comments
Steven Lord
Steven Lord on 4 Jan 2019
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 on 4 Jan 2019
Edited: John D'Errico on 4 Jan 2019
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. :)

Sign in to comment.

More Answers (1)

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

Categories

Find more on Mathematics in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!