Need Help With Function Creation and Integration

I am trying to create a code to use on an aerodynamics project, but I keep receiving error messages when I attempt to generate functions. For the functions themselves, I receive a "not enough input arguments" message, and I receive a lot of errors in integralcalc, including fx = FUN(t), [q,errbnd] = iterateScalarValued(u,tinterval,pathlen), [q,errbnd] = vadapt(@AtoBInvTransform,interval), and Q = integralCalc(fun,a,b,opstruct). How would I start to fix the errors?
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);

답변 (3개)

Chris
Chris 2023년 11월 10일
The full error output.
I am going to assume integralcalc was part of the stack that corresponded with the line ua
looking at the example here:
I am guessing your syntax is off in the function call to integral and the syntax should be:
ua = integral(funa(x,y,z,u_inf,c,delta),-b/2,b/2) - integral(funb(x,y,z,u_inf,c,delta),-b/2,b/2);
Torsten
Torsten 2023년 11월 10일
편집: Torsten 2023년 11월 10일
I'll assume that all variables except y0 are scalars and defined somewhere before in your code.
In this case, use
ua = integral(@(y0) funa(x,y,z,u_inf,c,delta,y0)-funb(x,y,z,u_inf,c,delta,y0),-b/2,b/2,'ArrayValued',true);
ub = integral(@(y0) func(x,y,z,u_inf,c,delta,y0)-fund(x,y,z,u_inf,c,delta,y0),-b/2,b/2,'ArrayValued',true);
instead of
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);
Or - if you don't want to use the "ArrayValued",true option because it's slow - vectorize your functions, i.e. make them evaluable for vector inputs for y0:
E.g.
funa = @(x,y,z,u_inf,c,delta,y0) (u_inf*delta)./sqrt((x-c)^2+(y-y0).^2+z^2);
instead of
funa = @(x,y,z,u_inf,c,delta,y0) (u_inf*delta)/sqrt(((x-c).^2)+(y-y0).^2+z.^2);

댓글 수: 1

Torsten
Torsten 2023년 11월 10일
편집: Torsten 2023년 11월 10일
Check the functions to be integrated. The integrals don't seem to exist in some cases.
delta = 0.05;
c = 1;
b = 2;
X = 0:0.1:1;
Y = 0:0.1:1;
z = 0;
u_inf = 10;
ua = zeros(numel(X),numel(Y));
ub = ua;
for i = 1:numel(X)
x = X(i);
for j = 1:numel(Y)
y = Y(j);
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(i,j) = integral(@(y0) funa(x,y,z,u_inf,c,delta,y0)-funb(x,y,z,u_inf,c,delta,y0),-b/2,b/2,'ArrayValued',true);
ub(i,j) = integral(@(y0) func(x,y,z,u_inf,c,delta,y0)-fund(x,y,z,u_inf,c,delta,y0),-b/2,b/2,'ArrayValued',true);
end
end

댓글을 달려면 로그인하십시오.

Steven Lord
Steven Lord 2023년 11월 10일

0 개 추천

What do you know (and have fixed values for) and what are you trying to integrate over?
Since nowhere in the code for the functions funa, funb, func, or fund do you define values for x, y, z, u_inf, c, or delta I'm assuming you've already created those variables and you're just trying to integrate these functions of y0? If so see the "Variables in the Expression" section on this documentation page. They don't need to be inputs to your anonymous function.
If that's not the case, can you show the mathematical form of the integrals you're trying to compute, state what you know, and state over which variable or variables you're trying to integrate?

댓글 수: 1

My values are set for this problem as:
delta = 0.05;
c = 1;
b = 2;
x = 0:0.1:1;
y = 0:0.1:1;
z = 0;
u_inf = 10;
I have fixed the problem with the integrals, but I'm still getting the "Not enough input arguments" error message when creating the function handles. I need the functions to then be able to integrate with them.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

제품

릴리스

R2021b

질문:

2023년 11월 10일

편집:

2023년 11월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by