What might be wrong with the code?

1 回表示 (過去 30 日間)
Sa Na
Sa Na 2021 年 12 月 28 日
編集済み: Chunru 2021 年 12 月 28 日
What might be wrong with the code ,it generates a straight line which is not required.
% The Boltzman Equation
E1=-13.6;
E2=-3.4;
k=8.617*10.^-5;
g1=2;
g2=8;
T=[5000;10000;15000;20000;25000];
N=[0.001;0.002;0.003;0.004;0.005];
% N=g2/g1*exp(-(E2-E1)/k*T);
set(gca,'xTicklabel',[5000 10000 15000 20000 25000]);
axis([5000 25000 0 0.05]);
xlabel('T')
ylabel('N2/N1')
plot(T,N);
The graph in the picture is required.

回答 (2 件)

KSSV
KSSV 2021 年 12 月 28 日
% The Boltzman Equation
E1=-13.6;
E2=-3.4;
k=8.617*10.^-5;
g1=2;
g2=8;
% T=[5000;10000;15000;20000;25000];
T = linspace(5000,25000) ;
% N=[0.001;0.002;0.003;0.004;0.005];
N=(g2/g1)*exp(-(E2-E1)./(k*T));
set(gca,'xTicklabel',[5000 10000 15000 20000 25000]);
axis([5000 25000 0 0.05]);
xlabel('T')
ylabel('N2/N1')
plot(T,N);

Chunru
Chunru 2021 年 12 月 28 日
編集済み: Chunru 2021 年 12 月 28 日
The data you plot is a straight line. The expected data should be something shown below.
E1=-13.6;
E2=-3.4;
k=8.617*10.^-5;
g1=2;
g2=8;
T=[5000:1000:25000];
%N=[0.001;0.002;0.003;0.004;0.005];
N=g2/g1*exp(-(E2-E1)./(k*T));
plot(T,N);
% set(gca,'xTicklabel',[5000 10000 15000 20000 25000]);
% axis([5000 25000 0 0.05]);
xlabel('T')
ylabel('N2/N1')
ax = gca; ax.XAxis.Exponent = 0;
%xtickformat('%g')
  3 件のコメント
Torsten
Torsten 2021 年 12 月 28 日
Chunru
Chunru 2021 年 12 月 28 日
See above.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by