How do I plot this graph?

1 回表示 (過去 30 日間)
Stefan Bras
Stefan Bras 2022 年 2 月 12 日
回答済み: Abraham Boayue 2022 年 2 月 12 日
I am heavily struggling to plot the following formula:
, where
x is supposed to be plotted on a logarithmic scale and both and Π are an array of 3 values. Moreover, .
I do not get an error, just weird graphs.
The code I made is the following. Could anyone tell me what I'm doing wrong here? Many thanks :-)
Pi_array = [0.5,1.5,4];
Cf_array = [0.0040,0.0028,0.0014];
K = 0.41;
x = linspace(10,1000);
Re_d=1.0.*10.^4;
w2 = @(x) 3.*x.^2-2.*x.^3;
for i=1:3
figure(2)
Pi2=Pi_array(i);
Cf2=Cf_array(i);
eta2= x.*(sqrt(2)./(sqrt(Cf2).*Re_d));
y2=(1./K).*log(eta2)-((2.*Pi2)./K).*(1-w2(x))+sqrt(2./Cf2);
hold on
semilogx(x,y2)
axis ([10 200 0 35])
end

採用された回答

David Hill
David Hill 2022 年 2 月 12 日
Cf= [0.0040,0.0028,0.0014];
Pi= [0.5,1.5,4];
K=0.41;
x = linspace(10,1000);
g =(sqrt(2./Cf)/10000)'.*x;
Re_d=1.0.*10.^4;
w = 3*g.^2-2*g.^3;
y=1/0.41*log(g)-(1-w).*((2*Pi/K)')+sqrt(2./Cf)';
semilogx(x,y);
  2 件のコメント
Stefan Bras
Stefan Bras 2022 年 2 月 12 日
編集済み: Stefan Bras 2022 年 2 月 12 日
Thanks for the fast answer David, you saved my day!
David Hill
David Hill 2022 年 2 月 12 日
You should check your equations.

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

その他の回答 (1 件)

Abraham Boayue
Abraham Boayue 2022 年 2 月 12 日
% Here is another code that you may find useful.
clear variables
close all
Cf = [0.0040,0.0028,0.0014];
Pi = [0.5,1.5,4];
N = length(Pi);
k = 0.41;
M = 1000;
xa = 10;
xb = 10000;
dx = (xb-xa)/(M-1);
x = xa:dx:xb;
Y = zeros(N,M);
for i= 1:length(Pi)
mu= (1/1000)*sqrt(2/Cf(i))*x;
w = 3*mu.^2-2*mu.^3 ;
y = 1/0.41*log(mu)-2*Pi(i)/k*(1-w)+sqrt(2/Cf(i));
Y(i,:)= y;
end
figure
plot(x,Y,'linewidth',2.5)
% semilogx(x,Y,'linewidth',2.5)
ax = title('y(x)');
set(ax,'fontsize',12);
ax= ylabel('y');
set(ax,'Fontsize',12);
ax = xlabel('x');
set(ax,'Fontsize',12);
axis ([10 400 -2500 500])
grid

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by