how can i calculate summation over two limits and that too inside a for loop for different values of x & z to have a graph as shown in figure that varies with change in frequency ?

조회 수: 2 (최근 30일)
clear
a=3.6;
b=4;
d=5.8;
k=(4*pi)/3;
w=12.5716e08;
e0=8.85e-12;
y=1.35;
x=[linspace(10,50,5)];
z=[linspace(10,50,5)];
x1=0.45;
y1=1.4;
z1=1.37;
e0n=2;
m = [linspace(4,100,97)];
n = [linspace(4,100,97)];
kx=(m*pi)/a;
ky=(n*pi)/b;
beta=sqrt(kx.^2+ky.^2-k^2);
E0=1/(w*e0);
E1=(2*e0n*sin(kx*x1).*cos(ky*y1))/(a*b*beta.*sin(beta*d));
E2=sum(E1);
E4=zeros(6);
E=zeros(6);
for x=10:10:50
    for z=10:10:50
        E3=(kx.*ky.*cos(kx.*x).*sin(ky*y).*sin(beta*z1).*sin(beta.*(d-z)))+((ky.^2-k^2).*sin(kx.*x).*cos(ky*y).*sin(beta*z1).*sin(beta.*(d-z)))+(ky.*beta.*sin(kx.*x).*sin(ky*y).*(-sin(beta*z1)).*cos(beta.*(d-z)));
        E4(x,z)=sum(E3);
    end
end
E(x,z)=E0*E2.*E4(x,z);
plot3(z,x,E)

(please let me know the corrections to make.thanks)

답변 (1개)

Eric
Eric 2018년 2월 1일
Okay, so there seem to be a lot of things going on (i.e. wrong) here, too much for someone else to solve for you. So a few points to get you started:
  • When you calculate E3, it appears you have taken all three E-field directions and smashed them into the same equation. You probably only want the y hat part of (2.21), namely ( z' here is "z prime")
% if z > z'
E3_y = (ky.^2-k^2).*sin(kx*x).*cos(ky*y) .* sin(beta*z ).*sin(beta*(d-z'));
% if z < z'
E3_y = (ky.^2-k^2).*sin(kx*x).*cos(ky*y) .* sin(beta*z').*cos(beta*(d-z ));
  • In your for loops, you'll want to use indexing, for example:
for i_x = 1:length(x)
for i_z = 1:length(z)
% Equations use x(i_x) and z(i_z), for example,
E4(i_x,i_z) = x(i_x).*z(i_z);
end
end
  • m and n in the photo start at 0 and go to infinity. Why did you choose 4:100? (Note: You might have issues if the equation doesn't converge quickly.)
  • m and n have separate indexing, so you need to separate them somehow, by indexing for example: (There are other, probably better, ways to do this though.)
for i_kx=1:length(kx)
% f(x,z,kx,ky) is the part in the summation
E_whatever(i_kx) = sum(f(x(i_x),z(i_z),kx(i_kx),ky;)
end
  • Add more points to x and z (make it about 100, at least) to get a better surface.
  • You'll eventually want to use meshgrid instead of your current linspace of x and z, and surf or mesh instead of your current plot3.
After you try all that, come back with your latest problems and maybe someone can get you a better answer. Good luck!

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by