end
disp(x2)
[L2,U3,P]=lu(A)
function [L,U]=guass(a,b)
n=size(a,1);
for j=1:n
U(1,j)=a(1,j);
end
for j=2:n
L(j,1)=a(j,1)/U(1,1);
end
for i=2:n
for j=i:n
s0=0;
for k=1:i-1
s0=s0+L(i,k)*U(k,j);
end
U(i,j)=a(i,j)-s0;
s1=0;
for k=1:i-1
s1=s1+L(j,k)*U(k,i);
end
L(j,i)=(a(j,i)-s1)/U(i,i);
end
end
for i=1:n
L(i,i)=1;
end
function [x]=luqj(L,U,b)
n=size(L,1);
y=zeros(n,1);
x=zeros(n,1);
y(1)=b(1)/L(1,1);
for i=2:n
s0=0;
for j=1:i-1
s0=s0+y(j)*L(i,j);
end
y(i)=(b(i)-s0)/L(i,i);
end
x(n)=y(n)/U(n,n);
for i=n-1:-1:1
s1=0;
for j=n:-1:i+1
s1=s1+x(j)*U(i,j);
end
x(i)=(y(i)-s1)/U(i,i);
评论22
最新资源