Matlab code - probably a simple mistake
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Paulo Silva
le 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 commentaires
Paulo Silva
le 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))
Voir également
Catégories
En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!