Need Help With Function Creation and Integration
1 次查看(过去 30 天)
显示 更早的评论
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);
0 个评论
回答(3 个)
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);
0 个评论
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
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
2023-11-10
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?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Computations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!