Issue with creating a plot from two for loops

2 ビュー (過去 30 日間)
Umar Naseef
Umar Naseef 2021 年 1 月 2 日
コメント済み: Umar Naseef 2021 年 1 月 2 日
Hi,
I have an issue with creating a plot in the same figure from two for loops.
This is my code which is quite simple but I am still unable to find the issue.
a=1.63279*10^-6;
b=264.9889;
for T=373:10:1273;
Mu = (a*T.^0.5)/(1+b./T)
plot(T, Mu)
end
n = 0.666;
T0 = 273;
Mu0 = 1.375*10^-5;
for T=373:10:1273;
MuT = Mu0.*(T./T0).^n
end
  1 件のコメント
Umar Naseef
Umar Naseef 2021 年 1 月 2 日
I should be creating 2 different graphs in the same plot from the same T values and the Mu and MuT values.

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

採用された回答

Star Strider
Star Strider 2021 年 1 月 2 日
Neither of the loops are necessary. Use element-wise operations (here, exponentiation (.^ instead of ^) and division (./ instead of /)) to create the plots:
a=1.63279*10^-6;
b=264.9889;
T=373:10:1273;
Mu = (a*T.^0.5)./(1+b./T);
figure
plot(T, Mu)
grid
n = 0.666;
T0 = 273;
Mu0 = 1.375*10^-5;
T=373:10:1273;
MuT = Mu0.*(T./T0).^n;
figure
plot(T, MuT)
grid
See the documentation on Array vs. Matrix Operations for a full explanation.
.
  2 件のコメント
Umar Naseef
Umar Naseef 2021 年 1 月 2 日
Got it. Thank you.
Star Strider
Star Strider 2021 年 1 月 2 日
As always, my pleasure!

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

その他の回答 (1 件)

David Hill
David Hill 2021 年 1 月 2 日
a=1.63279*10^-6;
b=264.9889;
T=373:10:1273;
Mu = (a*T.^0.5)./(1+b./T);
n = 0.666;
T0 = 273;
Mu0 = 1.375*10^-5;
MuT = Mu0.*(T./T0).^n;
plot(T, Mu,T,MuT);
  1 件のコメント
Umar Naseef
Umar Naseef 2021 年 1 月 2 日
This also works thank you.

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

カテゴリ

Help Center および File ExchangeArray Geometries and Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by