Set functions, returned "too many input arguments"

I'm working on a worksheet for an aerodynamics class. It's not graded, but it helps with the next project. I'm attempting to calculate the graph of the pressure coefficient (c_p) for a given x/c using a theory in class. I have completed the derivations, but when I attempt to create the functions and solve them, MATLAB produces an error message: "Error using codename>@(x,y,b)ln((sqrt(x^2+(y-(b/2))^2)+(y-(b/2)))/(sqrt(x^2+(y+(b/2))^2)+(y+(b/2)))) Too many input arguments."
How would I fix this and get my code to run? I have attached the code below:
clear;
clc;
delta = 0.05;
c = 1;
b = 2;
x = 0:0.1:1;
y = 0:0.1:1;
z = 0;
u_inf = 10;
%incompressible pressure coefficient
fun1 = @(x,y,b) ln((sqrt(x^2 + (y-(b/2))^2)+(y-(b/2)))/(sqrt(x^2 + (y+(b/2))^2)+(y+(b/2))));
fun2 = @(x,y,b) ln((sqrt((x-(c/2))^2 + (y-(b/2))^2)+(y-(b/2)))/(sqrt((x-(c/2))^2 + (y+(b/2))^2)+(y+(b/2))));
fun3 = @(x,y,b) ln((sqrt((x-c)^2 + (y-(b/2))^2)+(y-(b/2)))/(sqrt((x-c)^2 + (y+(b/2))^2)+(y+(b/2))));
xc = (0:.01:1);
cpi = @(x,y,b) -delta/pi.*(fun1(x,y,0,b) - 2*fun2(x,y,.5,b) + fun3(x,y,1,b) );
plot(xc,cpi(xc,0,b));
%compressible
%M < 1
funa = @(x,y,z,u_inf,c,delta,y0) (u_inf*delta)/sqrt(((x-c).^2)+(y-y0).^2+z.^2);
funb = @(x,y,z,u_inf,c,delta,y0) -(u_inf*delta)/sqrt(x.^2+(y-y0).^2+z.^2);
func = @(x,y,z,u_inf,c,delta,y0) (-2*u_inf*delta)/sqrt(((x-c).^2)+(y-y0).^2+z.^2);
fund = @(x,y,z,u_inf,c,delta,y0) (-2*u_inf*delta)/sqrt(((x-(c/2)).^2)+(y-y0).^2+z.^2);
ua = integral(@(y0) funa(x,y,z,u_inf,c,delta),-b/2,b/2) - integral(@(y0) funb(x,y,z,u_inf,c,delta),-b/2,b/2);
ub = integral(@(y0) func(x,y,z,u_inf,c,delta),-b/2,b/2) - integral(@(y0) fund(x,y,z,u_inf,c,delta),-b/2,b/2);
u_tot = (1/(2*pi))*(ua + ub);
M = 0.6;
bet = sqrt(1-M^2);
cpc = @(x,y) cpi(x,y*bet,b*bet)/bet;
hold on
plot(xc,cpc(xc,0))
set(gca,'ydir','reverse')
xlabel('x/c')
ylabel('c_p')

 Respuesta aceptada

Voss
Voss el 31 de Oct. de 2023
Editada: Voss el 31 de Oct. de 2023
fun1, fun2, and fun3 each take three inputs:
fun1 = @(x,y,b) ln((sqrt(x^2 + (y-(b/2))^2)+(y-(b/2)))/(sqrt(x^2 + (y+(b/2))^2)+(y+(b/2))));
fun2 = @(x,y,b) ln((sqrt((x-(c/2))^2 + (y-(b/2))^2)+(y-(b/2)))/(sqrt((x-(c/2))^2 + (y+(b/2))^2)+(y+(b/2))));
fun3 = @(x,y,b) ln((sqrt((x-c)^2 + (y-(b/2))^2)+(y-(b/2)))/(sqrt((x-c)^2 + (y+(b/2))^2)+(y+(b/2))));
% ^ ^ ^
% 1 2 3
But you are giving them 4 inputs:
cpi = @(x,y,b) -delta/pi.*(fun1(x,y,0,b) - 2*fun2(x,y,.5,b) + fun3(x,y,1,b) );
% ^ ^ ^ ^ ^ ^ ^^ ^ ^ ^ ^ ^
% 1 2 3 4 1 2 3 4 1 2 3 4

1 comentario

Steven Lord
Steven Lord el 31 de Oct. de 2023
In addition, the function to compute the natural logarithm in MATLAB is log not ln. There are other functions to compute the base 10 and base 2 logarithms (log10 and log2 respectively.)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programming en Centro de ayuda y File Exchange.

Productos

Versión

R2021b

Etiquetas

Preguntada:

el 31 de Oct. de 2023

Comentada:

el 31 de Oct. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by