How to plot contour ?
clc
clear
close all
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Define material properties and simulation parameters
n0 = 1; % Refractive index of air
ns = 1.46; % Refractive index of subtrate
% Parameters
lambda0=5e-6; % Wavelength of light in micrometers
frequency = linspace(58,67,1000);
c=3e8;
transmission=zeros(1,1000);
n01 = 1.578; % Refractive index of PS
n02 = 1.484; % Refractive index of PMMA
n=25;
nA = n01;
dA = lambda0/(4*nA); %% Thickness of First Layer in meters
nB = n02;
dB = lambda0/(4*nB); %% Thickness of Second Layer in meters
for i = 1:length(frequency)
f = frequency(i);
w=2*pi*f*1e12; %%% Angular frequency by frequency
DAA=dA * nA * (w/c);
DBB=dB * nB * (w/c);
%%% Transfer Matrix elements of first layer
ma11=cos(DAA); ma12=-1i*sin(DAA)/nA; ma21=-1i*nA*sin(DAA); ma22=cos(DAA);
MA=[ma11 ma12; ma21 ma22];
%%% Transfer MAtrix elements of Second layer
lb11=cos(DBB); lb12=-1i*sin(DBB)/nB; lb21=-1i*nB*sin(DBB); lb22=cos(DBB);
MB=[lb11 lb12; lb21 lb22];
M_total_P = (MB*MA)^n*(MA*MB)^n;
T1 = (2*ns/(ns*M_total_P(1,1)+ns*n0*M_total_P(1,2)+M_total_P(2,1)+n0*M_total_P(2,2)));
T=(n0 / ns) * abs(T1)^2;
transmission(i) = T;
end
plot(frequency,transmission)
this code is transmission spectra
I need a contour plot of this by varying the n01 and n02 with respect to Q factor
I did a program but is not working
can anyone help me
clc
clear
close all
tic
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Define material properties and simulation parameters
P = 0; %%% Hydrostatic pressure in MPa
n0 = 1; % Refractive index of air
ns = 1.46; % Refractive index of subtrate
% Parameters
lambda0=5e-6; % Wavelength of light in micrometers
%%% frequency Range
% f = 61.25; %% frequency in THz
frequency = linspace(58,67,1000);
c=3e8;
transmission=zeros(1,1000);
n01_ = linspace(1.3,4,25); % Refractive index of PS
n02_ = linspace(1.3,4,25); % Refractive index of PMMA
n=25;
% Q factor array
Q_factor_ = zeros(length(n01_), length(n02_));
for ii = 1:length(n01_)
n01 = n01_(ii);
nA = n01;
dA = lambda0/(4*nA); %% Thickness of First Layer in meters (varying with respect to n01)
for jj = 1:length(n02_)
n02 = n02_(jj);
nB = n02;
dB = lambda0/(4*nB); %% Thickness of Second Layer in meters (varying with respect to n02)
for i = 1:length(frequency)
f = frequency(i);
w=2*pi*f*1e12; %%% Angular frequency by frequency
DAA=dA * nA * (w/c); %%% (varying with respect to n01)
DBB=dB * nB * (w/c); %%% (varying with respect to n02)
%%% Transfer Matrix elements of first layer
ma11=cos(DAA); ma12=-1i*sin(DAA)/nA; ma21=-1i*nA*sin(DAA); ma22=cos(DAA);
MA=[ma11 ma12; ma21 ma22];
%%% Transfer MAtrix elements of Second layer
lb11=cos(DBB); lb12=-1i*sin(DBB)/nB; lb21=-1i*nB*sin(DBB); lb22=cos(DBB);
MB=[lb11 lb12; lb21 lb22];
M_total_P = (MB*MA)^n*(MA*MB)^n;
T1 = (2*ns/(ns*M_total_P(1,1)+ns*n0*M_total_P(1,2)+M_total_P(2,1)+n0*M_total_P(2,2)));
T=(n0 / ns) * abs(T1)^2;
transmission(i) = T;
desired_freq = 60;
peak_idx = find((frequency) == (desired_freq));
peak_val = transmission(peak_idx);
half_max = peak_val / 2;
peak_left_edge = find(transmission(1:peak_idx) < half_max, 1, ‘last’);
peak_right_edge = find(transmission(peak_idx:end) < half_max, 1, ‘first’) + peak_idx – 1;
fwhm = frequency(peak_right_edge) – frequency(peak_left_edge); %%% full width at half maximum
% Calculate Q factor
Q = desired_freq ./ fwhm;
% Store Q factor in array
Q_factor_(:,:,i) = Q;
end
end
end
contourf(n01_,n02_,Q_factor_)clc
clear
close all
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Define material properties and simulation parameters
n0 = 1; % Refractive index of air
ns = 1.46; % Refractive index of subtrate
% Parameters
lambda0=5e-6; % Wavelength of light in micrometers
frequency = linspace(58,67,1000);
c=3e8;
transmission=zeros(1,1000);
n01 = 1.578; % Refractive index of PS
n02 = 1.484; % Refractive index of PMMA
n=25;
nA = n01;
dA = lambda0/(4*nA); %% Thickness of First Layer in meters
nB = n02;
dB = lambda0/(4*nB); %% Thickness of Second Layer in meters
for i = 1:length(frequency)
f = frequency(i);
w=2*pi*f*1e12; %%% Angular frequency by frequency
DAA=dA * nA * (w/c);
DBB=dB * nB * (w/c);
%%% Transfer Matrix elements of first layer
ma11=cos(DAA); ma12=-1i*sin(DAA)/nA; ma21=-1i*nA*sin(DAA); ma22=cos(DAA);
MA=[ma11 ma12; ma21 ma22];
%%% Transfer MAtrix elements of Second layer
lb11=cos(DBB); lb12=-1i*sin(DBB)/nB; lb21=-1i*nB*sin(DBB); lb22=cos(DBB);
MB=[lb11 lb12; lb21 lb22];
M_total_P = (MB*MA)^n*(MA*MB)^n;
T1 = (2*ns/(ns*M_total_P(1,1)+ns*n0*M_total_P(1,2)+M_total_P(2,1)+n0*M_total_P(2,2)));
T=(n0 / ns) * abs(T1)^2;
transmission(i) = T;
end
plot(frequency,transmission)
this code is transmission spectra
I need a contour plot of this by varying the n01 and n02 with respect to Q factor
I did a program but is not working
can anyone help me
clc
clear
close all
tic
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Define material properties and simulation parameters
P = 0; %%% Hydrostatic pressure in MPa
n0 = 1; % Refractive index of air
ns = 1.46; % Refractive index of subtrate
% Parameters
lambda0=5e-6; % Wavelength of light in micrometers
%%% frequency Range
% f = 61.25; %% frequency in THz
frequency = linspace(58,67,1000);
c=3e8;
transmission=zeros(1,1000);
n01_ = linspace(1.3,4,25); % Refractive index of PS
n02_ = linspace(1.3,4,25); % Refractive index of PMMA
n=25;
% Q factor array
Q_factor_ = zeros(length(n01_), length(n02_));
for ii = 1:length(n01_)
n01 = n01_(ii);
nA = n01;
dA = lambda0/(4*nA); %% Thickness of First Layer in meters (varying with respect to n01)
for jj = 1:length(n02_)
n02 = n02_(jj);
nB = n02;
dB = lambda0/(4*nB); %% Thickness of Second Layer in meters (varying with respect to n02)
for i = 1:length(frequency)
f = frequency(i);
w=2*pi*f*1e12; %%% Angular frequency by frequency
DAA=dA * nA * (w/c); %%% (varying with respect to n01)
DBB=dB * nB * (w/c); %%% (varying with respect to n02)
%%% Transfer Matrix elements of first layer
ma11=cos(DAA); ma12=-1i*sin(DAA)/nA; ma21=-1i*nA*sin(DAA); ma22=cos(DAA);
MA=[ma11 ma12; ma21 ma22];
%%% Transfer MAtrix elements of Second layer
lb11=cos(DBB); lb12=-1i*sin(DBB)/nB; lb21=-1i*nB*sin(DBB); lb22=cos(DBB);
MB=[lb11 lb12; lb21 lb22];
M_total_P = (MB*MA)^n*(MA*MB)^n;
T1 = (2*ns/(ns*M_total_P(1,1)+ns*n0*M_total_P(1,2)+M_total_P(2,1)+n0*M_total_P(2,2)));
T=(n0 / ns) * abs(T1)^2;
transmission(i) = T;
desired_freq = 60;
peak_idx = find((frequency) == (desired_freq));
peak_val = transmission(peak_idx);
half_max = peak_val / 2;
peak_left_edge = find(transmission(1:peak_idx) < half_max, 1, ‘last’);
peak_right_edge = find(transmission(peak_idx:end) < half_max, 1, ‘first’) + peak_idx – 1;
fwhm = frequency(peak_right_edge) – frequency(peak_left_edge); %%% full width at half maximum
% Calculate Q factor
Q = desired_freq ./ fwhm;
% Store Q factor in array
Q_factor_(:,:,i) = Q;
end
end
end
contourf(n01_,n02_,Q_factor_) clc
clear
close all
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Define material properties and simulation parameters
n0 = 1; % Refractive index of air
ns = 1.46; % Refractive index of subtrate
% Parameters
lambda0=5e-6; % Wavelength of light in micrometers
frequency = linspace(58,67,1000);
c=3e8;
transmission=zeros(1,1000);
n01 = 1.578; % Refractive index of PS
n02 = 1.484; % Refractive index of PMMA
n=25;
nA = n01;
dA = lambda0/(4*nA); %% Thickness of First Layer in meters
nB = n02;
dB = lambda0/(4*nB); %% Thickness of Second Layer in meters
for i = 1:length(frequency)
f = frequency(i);
w=2*pi*f*1e12; %%% Angular frequency by frequency
DAA=dA * nA * (w/c);
DBB=dB * nB * (w/c);
%%% Transfer Matrix elements of first layer
ma11=cos(DAA); ma12=-1i*sin(DAA)/nA; ma21=-1i*nA*sin(DAA); ma22=cos(DAA);
MA=[ma11 ma12; ma21 ma22];
%%% Transfer MAtrix elements of Second layer
lb11=cos(DBB); lb12=-1i*sin(DBB)/nB; lb21=-1i*nB*sin(DBB); lb22=cos(DBB);
MB=[lb11 lb12; lb21 lb22];
M_total_P = (MB*MA)^n*(MA*MB)^n;
T1 = (2*ns/(ns*M_total_P(1,1)+ns*n0*M_total_P(1,2)+M_total_P(2,1)+n0*M_total_P(2,2)));
T=(n0 / ns) * abs(T1)^2;
transmission(i) = T;
end
plot(frequency,transmission)
this code is transmission spectra
I need a contour plot of this by varying the n01 and n02 with respect to Q factor
I did a program but is not working
can anyone help me
clc
clear
close all
tic
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Define material properties and simulation parameters
P = 0; %%% Hydrostatic pressure in MPa
n0 = 1; % Refractive index of air
ns = 1.46; % Refractive index of subtrate
% Parameters
lambda0=5e-6; % Wavelength of light in micrometers
%%% frequency Range
% f = 61.25; %% frequency in THz
frequency = linspace(58,67,1000);
c=3e8;
transmission=zeros(1,1000);
n01_ = linspace(1.3,4,25); % Refractive index of PS
n02_ = linspace(1.3,4,25); % Refractive index of PMMA
n=25;
% Q factor array
Q_factor_ = zeros(length(n01_), length(n02_));
for ii = 1:length(n01_)
n01 = n01_(ii);
nA = n01;
dA = lambda0/(4*nA); %% Thickness of First Layer in meters (varying with respect to n01)
for jj = 1:length(n02_)
n02 = n02_(jj);
nB = n02;
dB = lambda0/(4*nB); %% Thickness of Second Layer in meters (varying with respect to n02)
for i = 1:length(frequency)
f = frequency(i);
w=2*pi*f*1e12; %%% Angular frequency by frequency
DAA=dA * nA * (w/c); %%% (varying with respect to n01)
DBB=dB * nB * (w/c); %%% (varying with respect to n02)
%%% Transfer Matrix elements of first layer
ma11=cos(DAA); ma12=-1i*sin(DAA)/nA; ma21=-1i*nA*sin(DAA); ma22=cos(DAA);
MA=[ma11 ma12; ma21 ma22];
%%% Transfer MAtrix elements of Second layer
lb11=cos(DBB); lb12=-1i*sin(DBB)/nB; lb21=-1i*nB*sin(DBB); lb22=cos(DBB);
MB=[lb11 lb12; lb21 lb22];
M_total_P = (MB*MA)^n*(MA*MB)^n;
T1 = (2*ns/(ns*M_total_P(1,1)+ns*n0*M_total_P(1,2)+M_total_P(2,1)+n0*M_total_P(2,2)));
T=(n0 / ns) * abs(T1)^2;
transmission(i) = T;
desired_freq = 60;
peak_idx = find((frequency) == (desired_freq));
peak_val = transmission(peak_idx);
half_max = peak_val / 2;
peak_left_edge = find(transmission(1:peak_idx) < half_max, 1, ‘last’);
peak_right_edge = find(transmission(peak_idx:end) < half_max, 1, ‘first’) + peak_idx – 1;
fwhm = frequency(peak_right_edge) – frequency(peak_left_edge); %%% full width at half maximum
% Calculate Q factor
Q = desired_freq ./ fwhm;
% Store Q factor in array
Q_factor_(:,:,i) = Q;
end
end
end
contourf(n01_,n02_,Q_factor_) contour, plot, for loop MATLAB Answers — New Questions