guassian elimination with partial pivoting
조회 수: 1 (최근 30일)
이전 댓글 표시
hi, i'm trying to solve for a system of linear equation in form of matrices and i have made a function to perform the backward subtitute after doing all the pivoting and solve for the case where it has infinite solution only. this is what i got so far:
function x = backsub_syms(U,b)
n = length(b);
syms x [1 n]
u = rank(U);
p = n - u;
if (p == 1)
syms t
x(1,n)= t;
else if (p>1)
????????????????
end
end
for i=n-1:-1:1
m =1/U(i,i).*(b(i)-sum(U(i,i+1:end).*x(1,i+1:end)));
x(1,i)= m;
end
x=x(1,:)';
end
it is working perfectly fine only when the 1 free variable (p = 1) so in case p is larger than 1, i dont know how to approach this since this can only use symbolic variable to calculate. can some one give me an idea or a hint to complete the '??????' part
댓글 수: 0
채택된 답변
Keyur Mistry
2020년 9월 21일
I understand that you want to generalize your code for ‘p>1’. Find following hints to achieve it.
As there will be ‘p’ numbers of free variables, symbolic variable array can be defined ‘t1’,’t2’,…’tp’ as below
syms t [1 p];
for i=n:-1:n-p+1
x(1,i) = t(1,p-n+i); %if first non-zero entry in each row of U is diagonal element
end
It is necessary to find first non-zero entry for each row of ‘U’ to get correct solution. For the same find below code.
for i=n-p:-1:1
j=1;
d=U(i,j);
while d==0
j=j+1;
d=U(i,j);
end
m =1/d.*(b(i)-sum(U(i,j+1:end).*x(1,j+1:end)));
x(1,j) = m;
end
I hope these are useful hints to find your solution.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Linear Algebra에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!