Warning: MATLAB Toolbox Path Cache is out of date and is not being used.
Type 'help toolbox_path_cache' for more info.
To get started, select MATLAB Help or Demos from the Help menu.
>> function [y,n]=jacobi(A,b,x0,eps)
if nargin==3
eps=1.0e-6;
elseif nargin<3
error
return
end
D=diag(diag(A)); %求A的对角矩阵
L=-tril(A,-1); %求A的下三角阵
U=-triu(A,1); %求A的上三角阵
B=D\(L+U);
f=D\b;
y=B*x0+f;
n=1; %迭代次数
while norm(y-x0)>=eps
x0=y;
y=B*x0+f;
n=n+1;
end
??? function [y,n]=jacobi(A,b,x0,eps)
|
Error: Function definitions are not permitted at the prompt or in scripts.
>> A=[10,-1,0;-1,10,-2;0,-2,10]
A =
10 -1 0
-1 10 -2
0 -2 10
>> b=[9,7,6]'
b =
9
7
6
>> [x,n]=jacobi(A,b,[0,0,0]',1.0e-6)
??? Undefined command/function 'jacobi'.
>> A=[10,-1,0;-1,10,-2;0,-2,10];
b=[9,7,6]';
[x,n]=jacobi(A,b,[0,0,0]',1.0e-6)
??? Undefined command/function 'jacobi'.
>>
|