Borrar filtros
Borrar filtros

guassian elimination with partial pivoting

1 visualización (últimos 30 días)
nguyễn gia bảo
nguyễn gia bảo el 18 de Sept. de 2020
Respondida: Keyur Mistry el 21 de Sept. de 2020
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

Respuesta aceptada

Keyur Mistry
Keyur Mistry el 21 de Sept. de 2020
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.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by