Index exceeds the number of array elements
Afficher commentaires plus anciens
Hi,
I've come across this program to show the 3d radiation plot for a dipole but I've come across an error
-Code-
clear all
clc
format short g
syms z theta lambda R
prompt = 'Enter the frequency=? ';
freq = input(prompt);
prompt = 'Enter the antenna size=? ';
length = input(prompt);
L = round(length*freq/3e8,3)*lambda; %Length of antenna in terms of lambda
k0 = 2*pi/lambda; %Phase constant
z0 = 120*pi; %Intrinsic impedance
I = sin(k0*(L/2-abs(z))); %Current distribution
E(theta,lambda,R) = (1i*z0*k0*sin(theta)*exp(-1i*k0*R)/(4*pi*R))*int(I*2*cos(k0*z*cos(theta)),z,0,L/2); %E-field at farzone
A=(1i*z0*k0*exp(-1i*k0*R)/(4*pi*R));
p=(sin(theta)*int(I*2*cos(k0*z*cos(theta)),z,0,L/2)); %The theta part of the E-field with the constant term
%Elimination the constant term from 'p'--%
Q=(int(diff(p),theta));
F = factor(Q,theta);
field_pattern(theta) = simplify(p/F(1));
%----------------------------------------%
new(theta)=simplify(Q/F(1));
new2 = matlabFunction(new);
%------------------------------------------3D-pattern plot--------------------%
v=0.1:pi/499:1*pi;
t=0:pi/499:2*pi;
t2=0:pi/499:pi;
[T,U] = meshgrid(t,v);
[T2,U2]=meshgrid(t2,v);
X = abs(new2(U)).*sin(U).*cos(T);
Y = abs(new2(U)).*sin(U).*sin(T);
Z = abs(new2(U)).*cos(U);
X2 = abs(new2(U2)).*sin(U2).*cos(T2);
Y2 = abs(new2(U2)).*sin(U2).*sin(T2);
Z2 = abs(new2(U2)).*cos(U2);
figure (1);
surf(X,Y,Z,abs(new2(U)));
shading interp
axis vis3d
axis equal
lighting gouraud
set(gca,'xtick',[])
set(gca,'xticklabel',[])
set(gca,'ytick',[])
set(gca,'yticklabel',[])
set(gca,'ztick',[])
set(gca,'zticklabel',[])
figure (2);
surf(X2,Y2,Z2,abs(new2(U2)));
shading interp
axis vis3d
axis equal
lighting gouraud
set(gca,'xtick',[])
set(gca,'xticklabel',[])
set(gca,'ytick',[])
set(gca,'yticklabel',[])
set(gca,'ztick',[])
set(gca,'zticklabel',[])
%---------------------------------E-field radiation pattern plot--------------%
figure (3);
theta3=0:0.01:2*pi;
polar(theta3,abs(field_pattern(theta3))); %E-field radiation pattern
title(['Antenna length: ' num2str(round(length*freq/3e8,3))]);
view([90 -90]);
%-----------------------------------------------------------------------------%
-Error-
Index exceeds the number of array elements (2).
Error in sym/factor (line 107)
multiplicity = double(c{k+1});
Error in dipole_pattern (line 20)
F = factor(Q,theta);
What do i adjust/change to remove the error?
Réponses (1)
Torsten
le 22 Mar 2022
Q=(int(diff(p),theta));
should be p, shouldn't it ?
2 commentaires
Bertrand Ang
le 22 Mar 2022
Ok, I now see from your comment that you want the function without "constant term".
But your p is not a polynomial. So what is the "constant term" ?
Maybe
pconst = subs(p,theta,0)
and define p afterwards as
p = p - pconst
?
Q=(int(diff(p),theta));
at least is not reliable for this task.
Catégories
En savoir plus sur Multidimensional Arrays dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!