Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Vectors must be the same lengths error
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi , here is my code.I got this error Vectors must be the same lengths.Can you help me to solve the problem.Thanks. if true format long
tic
N_cut=20;
eps0=(10^-9)/(36*pi);
mu0=4*pi*10^-7;
epsr1=1.;
epsr2=2.;
mur1=1.;
mur2=1.;
eps1=epsr1*eps0;
eps2=epsr2*eps0;
mu1=mur1*mu0;
mu2=mur2*mu0;
freq=6*10^8;
omeg=2*pi*freq;
k=omeg*sqrt(eps1*mu1);
lambda=2*pi/k;
R=0.4;
phi=0;
for n=1:N_cut
A=sqrt(pi.*k.*R./2).*besselh(n+0.5,2,k.*R);
A(isnan(A))=0;
bes_kur(n)=A;
B=sqrt(pi.*k.*R./2).*besselh(n+0.5,2,k.*R);
B(isnan(B))=0;
han_kur(n)=B;
C=-n.*sqrt(pi.*k./(2.*R)).*besselj(n+0.5,k.*R)+k.*sqrt(pi.*k.*R./2).*besselj(n-0.5,k.*R);
C(isnan(C))=0;
bes_kur_der(n)=C;
D=-n.*sqrt(pi.*k./(2.*R)).*besselh(n+0.5,2,k.*R)+k.*sqrt(pi.*k.*R./2).*besselh(n-0.5,2,k.*R);
D(isnan(D))=0;
han_kur_der(n)=D;
a(n)=(1i.^(-n)).*(2.*n+1)./(n.*(n+1));
b(n)=(-a(n)).*bes_kur_der(n)./han_kur_der(n);
c(n)=(-a(n)).*bes_kur(n)./han_kur(n);
end
for n=1:N_cut
L1=legendre(n,cosd(theta));
L11=legendre(n-1,cosd(theta));
L2(n,theta)=L1(2,:);
if n==1
L3(n,theta)=0.;
else
L3(n,theta)=L11(2,:);
end
L2_der(n,theta)=(1./(1-(cosd(theta)).^2)).*((-n).*cosd(theta).*L3(n)+((n+1).*L2(n)));
E_theta(n,theta)=(1i/k*R)*exp(-1i*k*R)*cosd(phi)*((1i.^n).*((b(n).*sind(theta).*L2_der(n,theta)-c(n).*L3(n,theta)./sind(theta))));
end
F_Etheta=sum(E_theta,2);
theta=1:length(F_Etheta):179;
figure
plot(theta,abs(F_Etheta))
grid on
end
댓글 수: 1
답변 (2개)
Jan
2013년 4월 8일
Please read and post the complete error message. It contains the failing line, which is very useful for solving the problem.
You can use the debugger also:
dbstop if error
Then run the program again. Matlab stops when the error occurs and you can inspect the local variables to find out, which operation is not well defined.
댓글 수: 0
Walter Roberson
2013년 4월 8일
Why are you using
theta=1:length(F_Etheta):179;
The only way that can be the same length as F_Etheta is if
floor(180/length(F_Etheta)) = length(F_Etheta)
or approximately
179 = length(F_Etheta)^2
so
length(F_Etheta) = sqrt(179)
which is between 13 and 14.
If you experiment with 1:13:179 then its length is 14, and 1:14:179 has length 13, so even if your length happens to be in the right approximate range, it is not possible to match the length of the two vectors.
댓글 수: 1
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!