How can i give multiple input values in this function?
Mostrar comentarios más antiguos
I have defined my function and I want to solve for P for multiple phi but it does not give me for different input values it soled for only one value.
I also tried to plot it but it does not give me any plot. Can anyone see my code and guide me it will be very helpfull for me. Thanks in advance.
Inuput values are (pi/6 , pi/3, pi/2, 2pi/3, 5pi/6, pi, 7pi/6, 4pi/3, 3pi/2, 5pi/3, 11pi/6).
function [P] = myfile(phi)
phi = [pi/6 pi/3 pi/2];
for i=1:length(phi)
A = 6*(0.8)*sin(phi);
B = 2+(0.8)*cos(phi);
C = 2+(0.8)^2;
D = (1+0.8*cos(phi)).^2;
P = (A.*B)/(C*D);
end
figure,plot(phi,P)
xlabel('Domain'),ylabel('Pressure'),
title('non-dimensional pressure'),
end
Respuesta aceptada
Más respuestas (1)
madhan ravi
el 7 de Dic. de 2018
Editada: madhan ravi
el 7 de Dic. de 2018
EDITED
Loop can be avoided:
Phi=pi/6:pi/6:11*pi/6;
P = myfunc(phi); % function call
function P = myfunc(phi) % function definition
A = 6*(0.8).*sin(phi);
B = 2+(0.8).*cos(phi);
C = 2+(0.8).^2;
D = (1+0.8.*cos(phi)).^2;
P = (A.*B)./(C.*D);
figure,plot(phi,P)
xlabel('Domain'),ylabel('Pressure'),
title('non-dimensional pressure'),
end

6 comentarios
Mirza Farrukh Baig
el 7 de Dic. de 2018
madhan ravi
el 7 de Dic. de 2018
so you have some file named myfile change it's name or delete it
Mirza Farrukh Baig
el 7 de Dic. de 2018
madhan ravi
el 7 de Dic. de 2018
Editada: madhan ravi
el 7 de Dic. de 2018
yes use interp1() using spline method to smoothen the curve or decrease the step size
FYI the below is the values I got(just copy and paste my edited answer and save it ina script and run it or save the function with the same name it has and just call it):
P =
Columns 1 through 3
0.854265687098479 1.92807139989114 3.63636363636364
Columns 4 through 6
6.99818508108637 12.5938246840688 3.09029394417163e-14
Columns 7 through 9
-12.5938246840688 -6.99818508108638 -3.63636363636364
Columns 10 through 11
-1.92807139989115 -0.85426568709848
Mirza Farrukh Baig
el 7 de Dic. de 2018
madhan ravi
el 7 de Dic. de 2018
xq = linspace(0,2*pi,1000);
Categorías
Más información sobre Exponents and Logarithms en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
