马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
我用高斯列主元消去法编个求解线性方程组Ax=b的程序,出错??? Strings passed to EVAL cannot contain function declarations.
请教大家是什么意思啊?
附程序:
function x=lzygauss(A,b)
%应用高斯列主元消去法解线性方程组Ax=b
%Input
-A is an N*N matrix
%
-b is N*1 matrix
%Output
-x is an N*1 matrix containing the solution to Ax=b
%Initialize -x ,y,the temporary storage matrix C,and the row
%permutation information matrix R
[N,N]=size(A);
x=zeros(N,1);
y=zeros(N,1);
z=zeros(N,1);
R=1:N;
for p=1:N-1
%Find the pivot row for colum p
[max1,j]=max(abs(A(p:N,p)));
%Interchange row p and j
c=A(p,:);
A(p,:)=A(j+p-1,:);
A(j+p-1,:)=c;
%R用来标定y的顺序
d=b(p);
b(p)=b(j+p-1);
b(j+p-1)=d;
if A(p,p)==0
'A is singular.No unique solution'
break;
end;
%calculate multiplier and place in sundiagonal portion of A
for k=p+1:N
mult=A(k,p)/A(p,p);
b(k)=b(k)-mult*b(p);
%A(p,:)=A(j+p-1,:);
%A(k,p)=mult;
A(k,p:N)=A(k,p:N)-mult*A(p,p:N);
end;
end;
for k=N:-1:1
x(k)=(b(k)-A(k,k+1:N)*x(k+1:N))/A(k,k);
end
[ 本帖最后由 eight 于 2007-12-18 12:56 编辑 ] |