Matlab code - probably a simple mistake
4 次查看(过去 30 天)
显示 更早的评论
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');
0 个评论
回答(1 个)
Paulo Silva
2011-9-2
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 个评论
Paulo Silva
2011-9-2
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))
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!