Matlab code - probably a simple mistake

조회 수: 8 (최근 30일)
Chris
Chris 2011년 9월 2일
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');

답변 (1개)

Paulo Silva
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
Chris
Chris 2011년 9월 2일
when you say removes all the zeros, are you referring to all the zeros from 0 to about 30? This just makes the graph from 30 to 140 now? is that what you mean?
It should look like the graph of square root of x to a degree
Paulo Silva
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))

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by