How do I plot this graph?

조회 수: 7 (최근 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 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