求助:关于分块矩阵的还原,为什么实行不了
%运用Jacobi迭代拟合出来的u关于x和y的矩阵function J=jac(A,b,u0,eps)
if nargin==3
eps=1.0e-8
elseif nargin<3
'error'
return
end
%定义内部节点矩阵u0
h=1;k=1;
x=0:h:17;y=0:k:10;
e=length(x)-2;f=length(y)-2;
u=zeros(e,f);
u0=u;
%定义外部节点p
p=zeros(e+2,e+2);
p(1,1:f+2)=0;p(e+2,1:f+2)=0;
p(1:e+2,1)=100;p(1:e+2,f+2)=100;
%定义系数矩阵A
A=zeros(e*f,e*f);
B=mat2cell(A,ones(e*f/e,1)*e,ones(e*f/e,1)*e);
d1=ones(e,1);d2=ones(e-1,1);
M=4*diag(d1)-diag(d2,1)-diag(d2,-1);
N=-eye(e);
B{1,1}=M;B{e,e}=M
for i=2:e-1
B{i,i}=M;B{i-1,i}=N;B{i+1,i}=N
end
A=cell2mat(B);
这里总是显示
??? function J=jac(A,b,u0,eps)
|
Error: Function definitions are not permitted at the prompt or in scripts.
%定义b
b=ones(e*f,1);
for i=1:e
for j=1:f
b(i+j)=p(i,j+1)+p(i+1,j)+p(i+2,j+1)+p(i+1,j+2)
end
end
%运用Jacobi迭代法计算
D=diag(diag(A));
D=inv(D);
L=tril(A,-1);
U=triu(A,1);
B=-D*(L+U);
f=D*b;
J=B*u0+f;
while norm(J-u0)>=eps
x0=J;
J=B*u0+f;
end
return 自己顶一下,拜托哪位高手指点一下,纠结这个矩阵的还原,想了好多方法还是不行~~实在想不出哪里出错了 对不起,我也不知道,帮不了忙! 你是不是函数的定义没有放在M文件中?
页:
[1]