+ Post New Thread
Results 1 to 3 of 3

28th December 2019, 15:54 #1
 Join Date
 Oct 2006
 Location
 Real Homeless
 Posts
 2,724
 Helped
 739 / 739
 Points
 17,696
 Level
 32
Solution of Linear Equation using MATLAB
Code:A = [ 1, 2, 1, 2, 3; 2, 4, 0, 3, 1; 1, 2, 1, 0, 1; 3, 6, 2, 5, 7; 2, 4, 3, 5, 8] b = [6, 7, 2, 16, 14].'
rank(A)=3
det(A)=0
So A*x = b does not have unique solution.
Solution x is x = d + t1*c1 + t2*c2.
Here
d = [5, 0, 3, 1, 0].'
c1 = [2, 1, 0, 0, 0].'
c2 = [2, 0, 3, 1, 1].'
t1 and t2 are any values.
How can I get this solution by MATLAB ?
Solution by pseudo inverse matrix of A gives following.
Code:pinv(A)*b => 0.5932 1.1864 0.0508 0.0169 1.0169
Last edited by pancho_hideboo; 28th December 2019 at 16:15.

Advertisement

28th December 2019, 19:27 #2
 Join Date
 Oct 2006
 Location
 Real Homeless
 Posts
 2,724
 Helped
 739 / 739
 Points
 17,696
 Level
 32
Re: Solution of Linear Equation using MATLAB
General solution can be given as following.
Code:x = pinv(A)*b + (eye(5)pinv(A)*A)*[t1,t2,t3,t4,t5].’

Advertisement

12th January 2020, 07:19 #3
 Join Date
 Oct 2006
 Location
 Real Homeless
 Posts
 2,724
 Helped
 739 / 739
 Points
 17,696
 Level
 32
Re: Solution of Linear Equation using MATLAB
Code:d = pinv(A)*b % particular solution c = eye(size(A, 2))  pinv(A)*A % homogeneous solutions fprintf( 2, 'rank(c)=%d\n', rank(c, 1e5) ); R = rref(c) % reduced row echelon form t = randn(size(c, 2), 1); x = d + c*t; % general solution for inhomogeneous equation fprintf(1, 'A*xb'), A*xb
Code:d = 0.5932 1.1864 0.0508 0.0169 1.0169 c = 0.8136 0.3729 0.1017 0.0339 0.0339 0.3729 0.2542 0.2034 0.0678 0.0678 0.1017 0.2034 0.7627 0.2542 0.2542 0.0339 0.0678 0.2542 0.0847 0.0847 0.0339 0.0678 0.2542 0.0847 0.0847 rank(c)=2 R = 1.0000 0 0 0.4687 0.0260 0 1.0000 0 0.9375 0.0521 0 0 1.0000 0.6458 0.3160 0 0 0 0 0 0 0 0 0 0 A*xb ans = 1.0e013 * 0.0178 0.1243 0.0533 0.0355 0
Code:M = [A, b]; % augmented matrix ZR = null(M, 'r') % rational basis for the null space d = ZR(1:end1, end) % particular solution c = ZR(1:end1, 1:end1) % homogeneous solutions t = randn(size(c, 2), 1); x = d + c*t; % general solution for inhomogeneous equation fprintf(1, 'A*xb'), A*xb
Code:ZR = 2 2 5 1 0 0 0 3 3 0 1 1 0 1 0 0 0 1 d = 5 0 3 1 0 c = 2 2 1 0 0 3 0 1 0 1 A*xb ans = 1.0e014 * 0 0.0888 0.0222 0.1776 0.1776
+ Post New Thread
Please login