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

 Respuesta aceptada

David Hill
David Hill el 12 de Feb. de 2022

0 votos

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 comentarios

Stefan Bras
Stefan Bras el 12 de Feb. de 2022
Editada: Stefan Bras el 12 de Feb. de 2022
Thanks for the fast answer David, you saved my day!
David Hill
David Hill el 12 de Feb. de 2022
You should check your equations.

Iniciar sesión para comentar.

Más respuestas (1)

Abraham Boayue
Abraham Boayue el 12 de Feb. de 2022

0 votos

% 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

Categorías

Más información sobre 2-D and 3-D Plots en Centro de ayuda y File Exchange.

Productos

Versión

R2021a

Etiquetas

Preguntada:

el 12 de Feb. de 2022

Respondida:

el 12 de Feb. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by