Set functions, returned "too many input arguments"

1 次查看(过去 30 天)
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')

采纳的回答

Voss
Voss 2023-10-31
编辑:Voss 2023-10-31
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 个评论
Steven Lord
Steven Lord 2023-10-31
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.)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Oceanography and Hydrology 的更多信息

标签

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by