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')

 Réponse acceptée

Voss
Voss le 31 Oct 2023
Modifié(e) : Voss le 31 Oct 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 commentaire

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.)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Centre d'aide et File Exchange

Produits

Version

R2021b

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by