Clear Filters
Clear Filters

Need Help With Function Creation and Integration

1 view (last 30 days)
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);

Answers (3)

Chris
Chris on 10 Nov 2023
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 on 10 Nov 2023
Edited: Torsten on 10 Nov 2023
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 Comment
Torsten
Torsten on 10 Nov 2023
Edited: Torsten on 10 Nov 2023
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

Sign in to comment.


Steven Lord
Steven Lord on 10 Nov 2023
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 Comment
Matthew Loewer
Matthew Loewer on 10 Nov 2023
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.

Sign in to comment.

Categories

Find more on Matrix Computations in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!