How do I plot this graph?

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 2-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