alac 发表于 2007-12-18 08:28

Strings passed to EVAL cannot contain function declarations 出错求助

我用高斯列主元消去法编个求解线性方程组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
=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

=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 编辑 ]

sigma665 发表于 2007-12-18 09:27

呃~,matlab里不是直接可以解吗

http://forum.vibunion.com/forum/thread-14808-1-1.html这是以前有人遇到的同样的问题

你再搜索下...

会很有帮助的:)

[ 本帖最后由 sigma665 于 2007-12-18 09:47 编辑 ]

sigma665 发表于 2007-12-18 09:41

%Linear equation system 'Ax=r' by Gauss elimination method.
%Written by: "Sobhan Rostami"
%MSc student of structure engineering of Azad university of kerman.
clc
clear all
%=================================================================
disp('Solution of N-equation "="')
n=input ('Enter number of Equations :');
A=input ('Enter Matrix :');
r=input ('Enter Matrix :');
D=A;d=r;
%-----------------------------------------------------------------
%create upper triangular matrix
s=0;
for j=1:n-1
    if A(j,j)==0
      k=j;
      for k=k+1:n
            if A(k,j)==0
                continue
            end
            break
      end
      B=A(j,:); C=r(j);
      A(j,:)=A(k,:); r(j)=r(k);
      A(k,:)=B; r(k)=C;
    end
    for i=1+s:n-1
      L=A(i+1,j)/A(j,j);
      A(i+1,:)=A(i+1,:)-L*A(j,:);
      r(i+1)=r(i+1)-L*r(j);
    end
    s=s+1;
end
%-----------------------------------------------------------------
%Solution of equations
x(n)=r(n)/A(n,n);
for i=n-1:-1:1
    sum=0;
    for j=i+1:n
      sum=sum+A(i,j)*x(j);
    end
    x(i)=(1/A(i,i))*(r(i)-sum);
end
%------------------------------
%Checking with matlab functions
p=inv(D)*d;
%------------------------------
%Output
disp('@----------------------------------------------------------@')
disp('Output =')
disp('Upper riangular Matrix =');disp(A)
disp('Matrix =');disp(r)
disp('solution of linear equations :');disp(x')
disp('solve with matlab functions(for checking):');disp(p)


Author: Sobhan Rostami
Summary: Solve N-equation
MATLAB Release: R2007a
Description: This Matlab program Solve N-equation with Gauss elimination method and check results with Matlab Function.

从别的公开的地方找来的,别人编的程序.
页: [1]
查看完整版本: Strings passed to EVAL cannot contain function declarations 出错求助