我已经写了一些代码,但是我的程序太慢了。问题如下:
我将构建矩阵“A”来解决 Ax=b 问题
我有一个球体(它可以是任何形状),从某个点可以看出,
我为每个点分配了一个坐标向量 [xyz]。
N 是点数。
请先加载(一)
clc
[rv,N,d0]=geometrySphere(5e-9,10); %# Nx3 matrix [x1 y1 z1;x2 y2 z2;... ].
%# geometrySphere is a function for replacicg the sphere with points.
L=(301:500)*1e-9; K=2*pi./L; %# 1x200 array
%some constants ==================
I=eye(3);
e0=1;
V=N*d0^3; aeq=(3*V/(4*pi))^(1/3);
E0y=ones(N,1);
E0z=E0y;
Cext=zeros(1,200);
Qext=zeros(1,200);
A=zeros(3,3,N^2);
%=================================
for i=1:N
r(i)=sqrt(rv(i,1)^2+rv(i,2)^2+rv(i,3)^2); %# r is the size of each vector
end
for i=1:N
for j=1:N
dx(i,j)=rv(i,1)-rv(j,1); %# The x component of distance between each 2 point
dy(i,j)=rv(i,2)-rv(j,2);
dz(i,j)=rv(i,3)-rv(j,3);
end
end
d=cat(3,dx,dy,dz); %# d is the distance between each 2 point (a 3D matrix)
nd=sqrt(dx.^2+dy.^2+dz.^2); %# Norm of rv vector
nx=d(:,:,1)./nd; ny=d(:,:,2)./nd; nz=d(:,:,3)./nd;
n=cat(3,nx,ny,nz); %# Unit vectors for points that construct my sphere
for s=1:length(L)
E0x=exp(1i*K(s)*rv(:,1))';
% 1x200 array in direction of x(in Cartesian coordinate system)
% Main Loop =================================================
p=1;
for ii=1:N
for jj=1:N
if ii==jj
A(:,:,p)=a(s)*eye(3); %# 3x3 , a is a 1x200 constant array
p=p+1; %# p is only a counter
else
A(:,:,p)=-exp(1i*K(s)*nd(ii,jj))/nd(ii,jj)*(-K(s)^2*([nx(ii,jj);ny(ii,jj);nz(ii,jj)]...
*[nx(ii,jj) ny(ii,jj) nz(ii,jj)]-I)+(1/nd(ii,jj)^2-1i*K(s)/nd(ii,jj))...
*(3*[nx(ii,jj);ny(ii,jj);nz(ii,jj)]*[nx(ii,jj) ny(ii,jj) nz(ii,jj)]-I));
p=p+1;
end
end
end
%===============================================================
B = reshape(permute(reshape(A,3,3*N,[]),[2 1 3]),3*N,[]).';
%# concatenation of N^2 3x3 matrixes into a 3Nx3N matrix
for i=1:N
E00(:,i)=[E0x(i) E0y(i) E0z(i)]';
end
b=reshape(E00,3*N,1);
P=inv(B)*b;
Cext(s)=(4*pi*K(s))*imag(b'*P);
Qext(s)=Cext(s)/(pi*aeq^2);
end
Qmax=max(Qext); Qext=Qext/Qmax;
L=L*1e9;
plot(L,Qext,'--');figure(gcf)
我不知道我可以清楚地解释吗?
你有什么建议吗?在此先感谢您的任何建议。
geometrySphere 其中 I 是 3x3 单位矩阵,nij nij 表示二元乘积。
(a) 运行一个函数后是:一个1x200的数组