Solve Linear Equation with Constraints on Variables

13 Ansichten (letzte 30 Tage)
THOMAS DEGAETANO
THOMAS DEGAETANO am 10 Sep. 2023
Kommentiert: Dyuman Joshi am 15 Sep. 2023
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!

Akzeptierte Antwort

Matt J
Matt J am 10 Sep. 2023
Bearbeitet: Matt J am 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]
A = 3×3
-1 1 1 1 -4 2 1 2 -4
C = [0;0;0];
B1=trustregprob(A.'*A,A.'*C,1)
B1 = 3×1
0.8165 0.4082 0.4082
  3 Kommentare
Bruno Luong
Bruno Luong am 10 Sep. 2023
B1=trustregprob(A.'*A,A*C,1)
Are you sure it's not A'*C ? ( assumsing C is not 0)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Dyuman Joshi
Dyuman Joshi am 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])
L = 
m = 
n = 
  15 Kommentare
THOMAS DEGAETANO
THOMAS DEGAETANO am 14 Sep. 2023
Bearbeitet: THOMAS DEGAETANO am 14 Sep. 2023
Thank you both for your efforts! @Bruno Luong, i honestly didnt understand what a full rank matrix was :)
@Dyuman Joshi, thanks for your help. The solution seems a bit more intense (for a lay person - level 1 mind you). My goals was to compare @Matt J's solution versus the solution presented by @Dyuman Joshi.
Based on @Dyuman Joshi's method presented, the values are practically the same between the two methods.
Thank you all for your support and knowledge!
Dyuman Joshi
Dyuman Joshi am 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.

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by