How do I plot this graph?
2 次查看(过去 30 天)
显示 更早的评论
I am heavily struggling to plot the following formula:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/892545/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/892550/image.png)
x is supposed to be plotted on a logarithmic scale and both
and Π are an array of 3 values. Moreover,
.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/892555/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/892560/image.png)
I do not get an error, just weird graphs.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/892565/image.jpeg)
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
0 个评论
采纳的回答
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 个评论
更多回答(1 个)
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/892675/image.jpeg)
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!