题目二:超市有 A、B、C 三种果篮,同时装有苹果、香蕉、橘子三种水果。现已知在 A 种
果篮中三种水果质量比为 2:2:1,B 种果篮中为 1:2:3,C 种果篮中为 3:1:1,超市制作一套 A 、
B、C 三种果篮样品需消耗苹果 6千克、香蕉 6千克、橘子 7.5千克。求三种果篮各重几许?
一、列方程组
设A、B、C三种果篮分别重 X、Y、Z千克
2X/5+Y/6+3Z/5=6
2X/5+2Y/6+Z/5=6
X/5+3Y/6+Z/5=7.5
二、 Gauss 法直接求解
1、 输入高斯法程序,保存为 Gauss.m 文件
function [x,det,index]=Gauss(A,b) [n,m]=size(A);nb=length(b);
if n~=m
error( The rows and columns of matrix A must be equal! );
return ;
end
if m~=nb
error( The columns of A must be equal the length of b! );
return ;
end
index=1;det=1;x=zeros(n,1);
for k=1:n-1
a_max=0;
for i=k:n
if abs(A(i,k))a_max a_max=abs(A(i,k));r=i;
end
end
i
原创力文档

文档评论(0)