Plotting a function with a given range of values.

8 ビュー (過去 30 日間)
Jesse Green
Jesse Green 2018 年 3 月 6 日
回答済み: Paul Shoemaker 2018 年 3 月 6 日
I understanding the basics of plotting an equation but for some reason I cannot get this work. I want to plot the equation for friction factor f=1/(1.8*log10(6.9/Re + (relr/3.7)^1.11))^2 in the range 2300<Re<2e7.
x = linspace(2300, 2e7, 100);
y = (1/(1.8*log10(6.9/x + (0.000965)^1.11)))^2
plot(x,y)
  1 件のコメント
Elias Gule
Elias Gule 2018 年 3 月 6 日
This will most probably give you an error.
Remember x is a vector. So you should use element-wise division "./" instead of "/". Even the squaring, you need to replace ^2 with .^2.

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

回答 (1 件)

Paul Shoemaker
Paul Shoemaker 2018 年 3 月 6 日
X is a vector in this case, so you have to alert Matlab to treat it on a per-element basis with the use of "." before division/multiplication/power operations.
y = (1./(1.8*log10(6.9./x + (0.000965)^1.11))).^2
Paul Shoemaker

カテゴリ

Help Center および File ExchangeNumerical Integration and Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by