Matlab code - probably a simple mistake
Ältere Kommentare anzeigen
I am trying to calculate kx, and ky. The conductivity in the x and y direction. The graph is supposed to look like a nice upwards curve, however mine fluxuates up and down(like a wave). I have checked my formulas, by inserting the values into the equation for L, the values of kx and ky appear to be correct. It seems as though the graphing part does not work tho.
I am going from L is 30 to 140, increments of 10. This is the only variable that changes. Here is my code:
clear
clc
% Constants
mfp = 31; % mean free path (nm)
k = 316.72; % conductivity (W / m*k)
% Equations
Lmax = 140;
dL=10;
L=30;
while L<=Lmax
kx(L)=k*(1-((2*mfp)/(3*3.14*L)));
ky(L)=k*(1-(mfp/(3*L)));
L= L+dL;
end
plot(kx,'-'),hold on, plot(ky,'--'), hold on, plot(k);
title(['Conductivity ']);
xlabel('Thickness (nm)','FontSize',14);
ylabel('Conductivity','FontSize',14);
leg1=legend('kx','ky');
Antworten (1)
Paulo Silva
am 2 Sep. 2011
You are just looking for plot(kx,ky) not all those plots
Also the calculations generate several zero values, that's why plot(kx,ky) shows many lines, you can plot just their values plot(kx,ky,'*') or ignore all the zeros and connect the points with one line:
clear
clc
% Constants
mfp = 31; % mean free path (nm)
k = 316.72; % conductivity (W / m*k)
% Equations
Lmax = 140;
dL=10;
L=30;
while L<=Lmax
kx(L)=k*(1-((2*mfp)/(3*3.14*L)));
ky(L)=k*(1-(mfp/(3*L)));
L= L+dL;
end
kx(~kx)=[];
ky(~ky)=[];
plot(kx,ky);
title(['Conductivity ']);
xlabel('Thickness (nm)','FontSize',14);
ylabel('Conductivity','FontSize',14);
5 Kommentare
Chris
am 2 Sep. 2011
Chris
am 2 Sep. 2011
Paulo Silva
am 2 Sep. 2011
that removes the zeros from the kx and ky vectors so you can get one line connecting all non zero points, I don't know if the results are correct that way, please check if they are correct, the line is there and it goes up like you said.
Chris
am 2 Sep. 2011
Paulo Silva
am 2 Sep. 2011
I don't know where the zeros are, I just noticed that they are messing up the result of the plot function and yes the result does look like plot(x,sqrt(x))
Kategorien
Mehr zu Mathematics finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!