plot three dimensional surface for this code

조회 수: 2 (최근 30일)
Habib
Habib 2014년 11월 14일
댓글: Habib 2014년 11월 15일
Hi every one.
I decided to plot three-dimensional surface for u3 but when i wrote mesh(r4,u3), the error of " Z must be a matrix not scalar or vector" is appeared. Now I want help to plot it, How can I do it?.please help me?
clear all
close all
clc
r_1=linspace(-1,1,100);
r_2=linspace(-1,1,100);
[r1,r2]=meshgrid(linspace(-1,1,100));
z2=4.2; % is the axial distance from the beam's narrowest point
z1=1;
L=z2-z1;
wvl=500; % is wavelength
k=2*pi./wvl;
w0=sqrt(wvl.*z1./pi); % is the waist size
% is the radius at which the field amplitude and intensity
% drop to 1/e and 1/e2 of their axial values, respectively
w1=w0.*sqrt(1+wvl.*z1./pi.*w0.^2);
w2=w0.*sqrt(1+wvl.*z2./pi.*w0.^2);
% is the radius of curvature of the beam's wavefronts
R1=z1.*(1+(pi.*w0.^2./wvl.*z1).^2);
R2=z2.*(1+(pi.*w0.^2./wvl.*z2).^2);
% mathematical form of Gaussian beam
u1=w0./w1.*exp((-1./w1.^2+1i.*pi./wvl.*R1).*(r1.^2+r2.^2)-1i.*k.*z1);
figure(1)
surf(r1,r2,real(u1))
K=zeros(1,length(r1));
u2=zeros(1,length(r1));
u3=zeros(1,length(r1));
r3=linspace(0,1,length(r1));
r4=linspace(0,1,length(r1));
for nn=1:100
for mm=1:100
K(nn,mm)=exp(-1i.*pi.*(r3(nn).^2+z1.^2+r4(mm).^2+z1.^2-2.*(r3(nn).*r4(mm)+z1.*z2))./(wvl.*L)-1i.*k.*L);
u2(nn,mm)=w0./w1.*exp((-1./w1.^2+1i.*pi./wvl.*R1).*(r3(nn).^2+r4(mm).^2)-1i.*k.*z1);
end
u3(nn)=trapz(r3,K(nn,:).*u1(nn,:));
end
figure(2)
mesh(r3,r4,u3)

답변 (1개)

Chad Greene
Chad Greene 2014년 11월 14일
Indeed, r3, r4, and u3 are all 1x100 arrays. Change mesh(r3,r4,u3) to plot3(r3,r4,u3) to see for yourself. You'll have to find a way to make u3 into a 2D matrix representing a surface instead of a 1D array representing a line.
  댓글 수: 1
Habib
Habib 2014년 11월 15일
thank you for your attention.
good luck

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by