如何用Matlab求解方程组
展开全部
参考现代数值计算
也可以直接用 x = a \ b;
function x = gauss_matric(a,b); %高斯消元法(列主消元)
A = [a b];
[r c] = size(A);
for i = 1 : r-1
[~, A_max] = max(abs(A(i:r,i)));
A_tmp = A(i,:);
A(i,:) = A(A_max+i-1,:);
A(A_max+i-1,:) = A_tmp;
for j = i+1 : r
A(j,:) = A(j,:)-A(i,:)/A(i,i)*A(j,i);
end
end
for i = r : -1 : 1
x_tmp = 0;
for j = r : -1 : i + 1
x_tmp = x_tmp + A(i,j)*x(j);
end
x(i) = (A(i,c)-x_tmp)/A(i,i);
end
end
除了以上还有 LU、QR等等方法
也可以直接用 x = a \ b;
function x = gauss_matric(a,b); %高斯消元法(列主消元)
A = [a b];
[r c] = size(A);
for i = 1 : r-1
[~, A_max] = max(abs(A(i:r,i)));
A_tmp = A(i,:);
A(i,:) = A(A_max+i-1,:);
A(A_max+i-1,:) = A_tmp;
for j = i+1 : r
A(j,:) = A(j,:)-A(i,:)/A(i,i)*A(j,i);
end
end
for i = r : -1 : 1
x_tmp = 0;
for j = r : -1 : i + 1
x_tmp = x_tmp + A(i,j)*x(j);
end
x(i) = (A(i,c)-x_tmp)/A(i,i);
end
end
除了以上还有 LU、QR等等方法
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询