Solve Linear Equation with Constraints on Variables
16 views (last 30 days)
Show older comments
I am trying to solve a system of linear equations with the following expressions:
A*B1 = C; where:
syms L1 L2 L3 m1 m2 m3 n1 n2 n3
A = [-1, 1, 1; 1,-4,2; 1, 2,-4]
B1 = [L1; m1; n1]
C = [0;0;0]
with the constraint that: L1^2 + m1^2 + n1^2 == 1. I keep getting an error with linsolve to solve the variables L1, m1, and n1.
Any help would be greatly appreacted!
0 Comments
Accepted Answer
Matt J
on 10 Sep 2023
Edited: Matt J
on 10 Sep 2023
You can use trustregprob from this FEX download,
to obtain a numerical least squares solution.
A = [-1, 1, 1; 1,-4,2; 1, 2,-4]
C = [0;0;0];
B1=trustregprob(A.'*A,A.'*C,1)
More Answers (1)
Dyuman Joshi
on 10 Sep 2023
syms L1 L2 L3 m1 m2 m3 n1 n2 n3
A = [-1, 1, 1; 1,-4,2; 1, 2,-4];
B1 = [L1; m1; n1];
C = [0;0;0];
%Equations to be solved
eqn1 = A*B1 == C;
eqn2 = L1^2+m1^2+n1^2 == 1;
[L,m,n] = solve([eqn1; eqn2], [L1,m1,n1])
15 Comments
Dyuman Joshi
on 15 Sep 2023
"i honestly didnt understand what a full rank matrix was"
If you are going to work and write code in MATLAB, I strongly recommend you understand the basics of Matrix algebra, because MATLAB is literally based on it.
See Also
Categories
Find more on Linear Algebra 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!













