i want to solve a set of homogeneous linear equation

7 views (last 30 days)
A = (n,n) :- a (n,n) order of matrix which i get from previous calculations
B = [1 , x1 , x2 , x3 , .......... xn]' :- vector in which 1st element is 1 and rest all are unknown of (n,1) order
C = [0 , 0 , 0 , 0 ]' :- null vector of (n,1) order
i want solution to A*B = C
that will give me values of B vectors

Accepted Answer

Dyuman Joshi
Dyuman Joshi on 22 Mar 2023
Note - Symbolic Toolbox required
Note that you might not get a solution for x depending upon the values of A.
One such example would be - A is an Identity matrix, any order greater than 1; or in this particular case, magic() of any odd order
%Random example
A=magic(6);
n=size(A,1);
syms x [n-1 1]
B=[1;x];
sol=solve(A*B==0,x)
sol = struct with fields:
x1: 1 x2: -1/2 x3: -1 x4: -1 x5: 1/2
  3 Comments
Dyuman Joshi
Dyuman Joshi on 22 Mar 2023
As I said earlier - "Note that you might not get a solution for x depending upon the values of A."
For the values you have for A, there is no solution for x.
P = 1.0e+04*[6.6064,-3.5642,0,0;-3.5642,6.6064,-3.5642,0;0,-3.5642,6.6064,-3.5642;0,0,-3.5642,3.2624];
na = size(P,1);
syms u [na-1 1]
Ba = [1; u];
%Let's solve for each equation corresponding to each row
y = P*Ba
y = 
%1st equation, get the value of u1
U1 = solve(y(1)==0)
U1 = 
%2nd equation, use u1 to get the value of u2
U2 = solve(subs(y(2),u1,U1)==0,u2)
U2 = 
Now we have two equations remaining to get the value of u3, and the values of u1 and u2 will only be correct if we get the same u3 from
%value of u3 from 3rd equation
U3_1 = solve(subs(y(3),[u1 u2],[U1 U2])==0,u3)
U3_1 = 
%value of u3 from 4th equation
U3_2 = solve(subs(y(4),u2,U2)==0,u3)
U3_2 = 
As you can see, the values of u3 are not the same and hence there are no unique values for which the equation P*Ba=0 is satisfied.
The empty output (i.e. 0x1 sym) denote that there is no solution to the equation.

Sign in to comment.

More Answers (1)

Torsten
Torsten on 23 Mar 2023
Edited: Torsten on 23 Mar 2023
Or use the following code to produce an optimal solution in the least-squares sense:
A =1.0e+04*[6.6064,-3.5642,0,0;-3.5642,6.6064,-3.5642,0;0,-3.5642,6.6064,-3.5642;0,0,-3.5642,3.2624]
A = 4×4
66064 -35642 0 0 -35642 66064 -35642 0 0 -35642 66064 -35642 0 0 -35642 32624
C = -A(:,1);
B = A(:,2:end)\C
B = 3×1
1.8535 2.4356 2.6609
A*[1;B]
ans = 4×1
0.2555 0.4735 0.6221 0.6797

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!