how to solve matrix equation?
2 views (last 30 days)
Show older comments
I want to solve a equation which has vector known elements and obvisouly the answer should be vector too.
x1=sym('x1',[121 1]);
x2=sym('x2',[121 1]);
s=solve(x1+x2==n1,x1.*x2==n2,[x1,x2]);
but I think I didn't write the right code coz it's been a long time that is busy and there is no answer yet. I really need your help.
0 Comments
Accepted Answer
Walter Roberson
on 22 Apr 2021
x1+x2=n1
x1*x2=n2
so
x2 = n1-x1
x1*(n1-x1) = n2
x1*n1-x1^2 = n2
x1^2 - x1*n1 + n2 = 0
and solve the quadratic to get x1 and then x2. There will be two solutions
Do this just for scalars to get the forms of the solutions. Then substitute in the vectors.
4 Comments
Walter Roberson
on 24 Apr 2021
format long g
A = rand(42,2);
Ainv = pinv(A);
Ainv * A
It isn't clear what you mean when you say that you want A * Ainv = 1 for a non-square matrix. Do you mean a matrix with all ones? Do you mean a non-square matrix in which the main diagonal is 1 and the rest is 0? What size do you expect A*Ainv to be?
More Answers (1)
See Also
Categories
Find more on Function Creation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!