声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1426|回复: 2

[编程技巧] Strings passed to EVAL cannot contain function declarations 出错求助

[复制链接]
发表于 2007-12-18 08:28 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

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 编辑 ]
回复
分享到:

使用道具 举报

发表于 2007-12-18 09:27 | 显示全部楼层
呃~,matlab里不是直接可以解吗

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

你再搜索下...

会很有帮助的  :)

[ 本帖最后由 sigma665 于 2007-12-18 09:47 编辑 ]
发表于 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 "[A][X]=[r]"')
n=input ('Enter number of Equations :');
A=input ('Enter Matrix [A]:');
r=input ('Enter Matrix [r]:');
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 [B][x]=')
disp('Upper riangular Matrix [B] =');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.

从别的公开的地方找来的,别人编的程序.
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-12-26 08:26 , Processed in 0.067497 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表