Welcome to Dream.In.Code
Getting Help is Easy!

Join 132,478 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,271 people online right now. Registration is fast and FREE... Join Now!




Matlab color plot

 
Reply to this topicStart new topic

Matlab color plot

agoral
post 2 Jul, 2008 - 08:02 AM
Post #1


New D.I.C Head

*
Joined: 2 Jul, 2008
Posts: 2

Hi,
I have been working on this code in matlab to create a color plot of contrast as a function of d2 and lambda. But I can't get it to work. I have tried to use pcolor and contourf. I am expecting the contrast to be on the order of 0 to 0.15, but I am getting 0 to -40. I have checked all of the equations and they are correct. Can anyone help me?

CODE

%Contrast(d2,lambda)
%indices for n2, refractive indices of SiO2
t = [1.4769372413793105 1.4761096551724138 1.4752820689655173 1.4745 1.4738828715365238 1.4732657430730478...
    1.4726486146095716 1.4720314861460957 1.4714143576826195 1.4707972292191436 1.4701801007556674...
    1.4695720257234728 1.4691057877813505 1.4686395498392282 1.468173311897106 1.4677070739549838...
    1.4672408360128617 1.4667745980707394 1.4663849999999998 1.4660099999999998 1.465635 1.46526...
    1.464885 1.46451 1.464155737704918 1.463827868852459 1.4635 1.463172131147541 1.462892...
    1.4626253333333334 1.4623586666666666 1.462092 1.4618328 1.4615928 1.4613528 1.4611128 1.4608728...
    1.4606328 1.4603928 1.4601528 1.4599485436893203 1.459754368932039 1.4595601941747574...
    1.4593660194174758 1.4591718446601942 1.4589776699029127 1.4587682352941178 1.4585917647058824...
    1.4583781651376146 1.4582222018348623 1.4580662385321101 1.4579102752293578 1.4577543119266054...
    1.4575983486238533 1.457442385321101 1.4572864220183486 1.4571304587155964 1.456974495412844...
    1.456818532110092 1.4566712000000002 1.4565512 1.4564312 1.4563034782608695 1.4561730434782607...
    1.4560431524547803 1.455913953488372 1.4557847545219638 1.4556555555555555 1.4555263565891472...
    1.4553971576227391 1.4552679586563309 1.4551387596899226 1.4550375 1.4549482142857144 1.4548589285714286...
    1.4547696428571428 1.4546803571428573 1.4545910714285715 1.4545017857142857 1.4544125 1.4543232142857143];
%indices for n3, refractive indices of Si
s = [5.43578947368421-2.988473684210526i 5.656857142857141-3.0185714285714282i...
    6.051857142857142-2.9898095238095244i 6.546714285714283-2.669428571428575i...
    6.811-2.033090909090908i 6.736391304347825-1.3989130434782595i 6.469347826086958-0.9665217391304362i...
    6.185-0.714i 5.943760000000001-0.5587600000000003i 5.740399999999998-0.4543999999999993i...
    5.57-0.387i 5.425407407407407-0.33092592592592573i 5.296037037037037-0.2950740740740741i...
    5.186785714285715-0.2605000000000002i 5.088964285714286-0.23771428571428582i...
    5.0023793103448275-0.2098965517241379i 4.923500000000001-0.1955i 4.852161290322581-0.185i...
    4.787322580645162-0.16932258064516126i 4.7289375-0.15337500000000004i 4.673757575757576-0.14512121212121204i...
    4.623-0.13148484848484848i 4.575941176470589-0.13023529411764706i 4.5317428571428575-0.13305714285714287i...
    4.491777777777778-0.12i 4.4543243243243245-0.10540540540540558i 4.420216216216216-0.09335135135135131i...
    4.386578947368421-0.08226315789473686i 4.355307692307692-0.07802564102564102i 4.3253076923076925-0.07392307692307692i...
    4.297487804878049-0.07282926829268294i 4.271634146341463-0.06746341463414635i...
    4.245952380952381-0.0665714285714285i 4.222441860465116-0.06i 4.1999767441860465-0.056837209302325574i...
    4.178688888888888-0.05326666666666664i 4.1585777777777775-0.043044444444444434i 4.137829787234042-0.04538297872340428i...
    4.119744680851064-0.04723404255319147i 4.10175-0.044i 4.084428571428572-0.04057142857142841i...
    4.0682-0.033800000000000066i 4.052588235294118-0.03623529411764699i 4.037607843137255-0.03254901960784312i...
    4.0225660377358485-0.03301886792452832i 4.009222222222222-0.02944444444444445i...
    3.9954444444444444-0.0273333333333333i 3.9825-0.03i 3.97-0.03i 3.9585087719298246-0.027578947368421054i...
    3.9472586206896554-0.025655172413793104i 3.9366949152542374-0.025i 3.9262333333333337-0.024633333333333337i...
    3.915639344262295-0.023606557377049187i 3.905793650793651-0.022i 3.8954761904761903-0.022i...
    3.88646875-0.020218750000000008i 3.877569230769231-0.018630769230769232i 3.8683880597014926-0.017865671641791044i...
    3.8594328358208956-0.017119402985074632i 3.851205882352941-0.016382352941176466i 3.8435217391304346-0.016i...
    3.836225352112676-0.015929577464788725i 3.828478873239437-0.015225352112676047i 3.8208055555555553-0.014527777777777766i...
    3.813378378378378-0.013837837837837827i 3.8066216216216215-0.013162162162162157i 3.8005-0.013i...
    3.7945974025974025-0.013i 3.7887532467532465-0.013i 3.7830625-0.012562500000000006i 3.7773827160493827-0.011938271604938279i...
    3.77120987654321-0.011320987654320993i 3.765951219512195-0.011i 3.7616829268292684-0.011i...
    3.7565529411764707-0.010505882352941176i 3.751436781609195-0.01i 3.747413793103448-0.01i...
    3.7429775280898876-0.009775280898876405i 3.737921348314607-0.009213483146067417i 3.7332747252747254-0.009i];

%d2 = 5e-9:5e-9:405e-9;
%lambda = 350:5:750; %wavelength of visible range
for i = 1:81;
    d2 = i*5e-9;
    for j = 1:81;
        lambda = 345+5*j;
        
n0 = 1; %index of refraction of air
n1 = 2.6-1.3i; %index of refraction of graphene
d1 = 0.34e-9; %thickness of graphene
n2 = t(i);
n3 = s(i);

%define intensity
phi1 = 2*pi*n1*d1./(lambda*1e-9);
phi2 = 2*pi*n2*d2./(lambda*1e-9);
r1 = (n0-n1)./(n0+n1);
r2 = (n1-n2)./(n1+n2);
r3 = (n2-n3)./(n2+n3);
intensity = (abs((r1.*exp(i*(phi1+phi2))+r2.*exp(-i*(phi1-phi2))+r3.*exp(-i*(phi1+phi2))...
     +r1.*r2.*r3.*exp(i*(phi1-phi2))).*(exp(i*(phi1+phi2))+r1.*r2.*exp(-i*(phi1-phi2))...
     +r1.*r3.*exp(-i*(phi1+phi2))+r2.*r3.*exp(i*(phi1-phi2))).^-1)).^2;
%intensity with absence of graphene (n1=1)
phi1_n = 2*pi*d1./(lambda*1e-9);
phi2_n = 2*pi*n2*d2./(lambda*1e-9);
r1_n = (n0-1)./(n0+1);
r2_n = (1-n2)./(1+n2);
r3_n = r3;
intensity_n = (abs((r1_n.*exp(i*(phi1_n+phi2_n))+r2_n.*exp(-i*(phi1_n-phi2_n))...
     +r3_n.*exp(-i*(phi1_n+phi2_n))+r1_n.*r2_n.*r3_n.*exp(i*(phi1_n-phi2_n))).*...
     (exp(i*(phi1_n+phi2_n))+r1_n.*r2_n.*exp(-i*(phi1_n-phi2_n))+r1_n.*r3_n.*exp(-i*(phi1_n+phi2_n))...
     +r2_n.*r3_n.*exp(i*(phi1_n-phi2_n))).^-1)).^2;
%contrast
contrast(i,j) = (intensity_n-intensity)./intensity_n;
     end
end
A = 0:5:400;
B = 350:5:750;
pcolor(A,B,contrast)
xlabel('d2 (nm)')
ylabel('lambda (nm)')
colormap(jet)
colorbar
User is offlineProfile CardPM

Go to the top of the page

agoral
post 7 Jul, 2008 - 11:24 AM
Post #2


New D.I.C Head

*
Joined: 2 Jul, 2008
Posts: 2

I got it! Never mind.


QUOTE(agoral @ 2 Jul, 2008 - 09:02 AM) *

Hi,
I have been working on this code in matlab to create a color plot of contrast as a function of d2 and lambda. But I can't get it to work. I have tried to use pcolor and contourf. I am expecting the contrast to be on the order of 0 to 0.15, but I am getting 0 to -40. I have checked all of the equations and they are correct. Can anyone help me?

CODE

%Contrast(d2,lambda)
%indices for n2, refractive indices of SiO2
t = [1.4769372413793105 1.4761096551724138 1.4752820689655173 1.4745 1.4738828715365238 1.4732657430730478...
    1.4726486146095716 1.4720314861460957 1.4714143576826195 1.4707972292191436 1.4701801007556674...
    1.4695720257234728 1.4691057877813505 1.4686395498392282 1.468173311897106 1.4677070739549838...
    1.4672408360128617 1.4667745980707394 1.4663849999999998 1.4660099999999998 1.465635 1.46526...
    1.464885 1.46451 1.464155737704918 1.463827868852459 1.4635 1.463172131147541 1.462892...
    1.4626253333333334 1.4623586666666666 1.462092 1.4618328 1.4615928 1.4613528 1.4611128 1.4608728...
    1.4606328 1.4603928 1.4601528 1.4599485436893203 1.459754368932039 1.4595601941747574...
    1.4593660194174758 1.4591718446601942 1.4589776699029127 1.4587682352941178 1.4585917647058824...
    1.4583781651376146 1.4582222018348623 1.4580662385321101 1.4579102752293578 1.4577543119266054...
    1.4575983486238533 1.457442385321101 1.4572864220183486 1.4571304587155964 1.456974495412844...
    1.456818532110092 1.4566712000000002 1.4565512 1.4564312 1.4563034782608695 1.4561730434782607...
    1.4560431524547803 1.455913953488372 1.4557847545219638 1.4556555555555555 1.4555263565891472...
    1.4553971576227391 1.4552679586563309 1.4551387596899226 1.4550375 1.4549482142857144 1.4548589285714286...
    1.4547696428571428 1.4546803571428573 1.4545910714285715 1.4545017857142857 1.4544125 1.4543232142857143];
%indices for n3, refractive indices of Si
s = [5.43578947368421-2.988473684210526i 5.656857142857141-3.0185714285714282i...
    6.051857142857142-2.9898095238095244i 6.546714285714283-2.669428571428575i...
    6.811-2.033090909090908i 6.736391304347825-1.3989130434782595i 6.469347826086958-0.9665217391304362i...
    6.185-0.714i 5.943760000000001-0.5587600000000003i 5.740399999999998-0.4543999999999993i...
    5.57-0.387i 5.425407407407407-0.33092592592592573i 5.296037037037037-0.2950740740740741i...
    5.186785714285715-0.2605000000000002i 5.088964285714286-0.23771428571428582i...
    5.0023793103448275-0.2098965517241379i 4.923500000000001-0.1955i 4.852161290322581-0.185i...
    4.787322580645162-0.16932258064516126i 4.7289375-0.15337500000000004i 4.673757575757576-0.14512121212121204i...
    4.623-0.13148484848484848i 4.575941176470589-0.13023529411764706i 4.5317428571428575-0.13305714285714287i...
    4.491777777777778-0.12i 4.4543243243243245-0.10540540540540558i 4.420216216216216-0.09335135135135131i...
    4.386578947368421-0.08226315789473686i 4.355307692307692-0.07802564102564102i 4.3253076923076925-0.07392307692307692i...
    4.297487804878049-0.07282926829268294i 4.271634146341463-0.06746341463414635i...
    4.245952380952381-0.0665714285714285i 4.222441860465116-0.06i 4.1999767441860465-0.056837209302325574i...
    4.178688888888888-0.05326666666666664i 4.1585777777777775-0.043044444444444434i 4.137829787234042-0.04538297872340428i...
    4.119744680851064-0.04723404255319147i 4.10175-0.044i 4.084428571428572-0.04057142857142841i...
    4.0682-0.033800000000000066i 4.052588235294118-0.03623529411764699i 4.037607843137255-0.03254901960784312i...
    4.0225660377358485-0.03301886792452832i 4.009222222222222-0.02944444444444445i...
    3.9954444444444444-0.0273333333333333i 3.9825-0.03i 3.97-0.03i 3.9585087719298246-0.027578947368421054i...
    3.9472586206896554-0.025655172413793104i 3.9366949152542374-0.025i 3.9262333333333337-0.024633333333333337i...
    3.915639344262295-0.023606557377049187i 3.905793650793651-0.022i 3.8954761904761903-0.022i...
    3.88646875-0.020218750000000008i 3.877569230769231-0.018630769230769232i 3.8683880597014926-0.017865671641791044i...
    3.8594328358208956-0.017119402985074632i 3.851205882352941-0.016382352941176466i 3.8435217391304346-0.016i...
    3.836225352112676-0.015929577464788725i 3.828478873239437-0.015225352112676047i 3.8208055555555553-0.014527777777777766i...
    3.813378378378378-0.013837837837837827i 3.8066216216216215-0.013162162162162157i 3.8005-0.013i...
    3.7945974025974025-0.013i 3.7887532467532465-0.013i 3.7830625-0.012562500000000006i 3.7773827160493827-0.011938271604938279i...
    3.77120987654321-0.011320987654320993i 3.765951219512195-0.011i 3.7616829268292684-0.011i...
    3.7565529411764707-0.010505882352941176i 3.751436781609195-0.01i 3.747413793103448-0.01i...
    3.7429775280898876-0.009775280898876405i 3.737921348314607-0.009213483146067417i 3.7332747252747254-0.009i];

%d2 = 5e-9:5e-9:405e-9;
%lambda = 350:5:750; %wavelength of visible range
for i = 1:81;
    d2 = i*5e-9;
    for j = 1:81;
        lambda = 345+5*j;
        
n0 = 1; %index of refraction of air
n1 = 2.6-1.3i; %index of refraction of graphene
d1 = 0.34e-9; %thickness of graphene
n2 = t(i);
n3 = s(i);

%define intensity
phi1 = 2*pi*n1*d1./(lambda*1e-9);
phi2 = 2*pi*n2*d2./(lambda*1e-9);
r1 = (n0-n1)./(n0+n1);
r2 = (n1-n2)./(n1+n2);
r3 = (n2-n3)./(n2+n3);
intensity = (abs((r1.*exp(i*(phi1+phi2))+r2.*exp(-i*(phi1-phi2))+r3.*exp(-i*(phi1+phi2))...
     +r1.*r2.*r3.*exp(i*(phi1-phi2))).*(exp(i*(phi1+phi2))+r1.*r2.*exp(-i*(phi1-phi2))...
     +r1.*r3.*exp(-i*(phi1+phi2))+r2.*r3.*exp(i*(phi1-phi2))).^-1)).^2;
%intensity with absence of graphene (n1=1)
phi1_n = 2*pi*d1./(lambda*1e-9);
phi2_n = 2*pi*n2*d2./(lambda*1e-9);
r1_n = (n0-1)./(n0+1);
r2_n = (1-n2)./(1+n2);
r3_n = r3;
intensity_n = (abs((r1_n.*exp(i*(phi1_n+phi2_n))+r2_n.*exp(-i*(phi1_n-phi2_n))...
     +r3_n.*exp(-i*(phi1_n+phi2_n))+r1_n.*r2_n.*r3_n.*exp(i*(phi1_n-phi2_n))).*...
     (exp(i*(phi1_n+phi2_n))+r1_n.*r2_n.*exp(-i*(phi1_n-phi2_n))+r1_n.*r3_n.*exp(-i*(phi1_n+phi2_n))...
     +r2_n.*r3_n.*exp(i*(phi1_n-phi2_n))).^-1)).^2;
%contrast
contrast(i,j) = (intensity_n-intensity)./intensity_n;
     end
end
A = 0:5:400;
B = 350:5:750;
pcolor(A,B,contrast)
xlabel('d2 (nm)')
ylabel('lambda (nm)')
colormap(jet)
colorbar


User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/22/08 02:57PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month