Undefined operator '*' for input arguments of type 'function_handle' error in Integral2. Kindly help me clear this error.

2 次查看(过去 30 天)
CODE:
for d=0.1:0.1:1
A=0
r1=@(ai,aj) sqrt((x+ai).^2+(y+aj).^2+z.^2)
r2=@(ai,aj) sqrt((ai-x).^2+(y+aj).^2+z.^2)
r3=@(ai,aj) sqrt((ai-x).^2+(y-aj).^2+z.^2)
r4=@(ai,aj) sqrt((x+ai).^2+(y-aj).^2+z.^2)
C1=@(ai) ai+x
C4=@(ai) -C1
C2=@(ai) ai-x
C3=@(ai) -C2
d1=@(aj) y+aj
d2=@(aj) d1
d3=@(aj) y-aj
d4=@(aj) d3
Bz= @(ai,aj) (u0/(4*pi))*(((((-1)^1*d1)/(r1*(r1+((-1)^(1+1))*C1)))-(C1/(r1*(r1+d1))))+((((-1)^2*d2)/(r2*(r2+((-1)^(2+1))*C2)))-(C2/(r2*(r2+d2))))+((((-1)^3*d3)/(r3*(r3+((-1)^(3+1))*C3)))-(C3/(r3*(r3+d3))))+((((-1)^4*d4)/(r4*(r4+((-1)^(4+1))*C4)))-(C4/(r4*(r4+d4)))))
for ai=[a-2*(N-1)*wd-2*(N-1)*s a-2*(N-2)*wd-2*(N-2)*s a-2*(N-3)*wd-2*(N-3)*s a-2*(N-4)*wd-2*(N-4)*s a-2*(N-5)*wd-2*(N-5)*s]
for aj=[a-2*(N-1)*wd-2*(N-1)*s a-2*(N-2)*wd-2*(N-2)*s a-2*(N-3)*wd-2*(N-3)*s a-2*(N-4)*wd-2*(N-4)*s a-2*(N-5)*wd-2*(N-5)*s]
M=integral2(Bz,0,ai,0,aj)
A=A+M
hold on
end
end
end
ERROR: Undefined operator '*' for input arguments of type 'function_handle'.
Error in FPSSConlyM3 (line 62)
M=integral2(Bz,0,ai,0,aj)

采纳的回答

Walter Roberson
Walter Roberson 2019-8-14
You have
d1=@(aj) y+aj
and
Bz= @(ai,aj) (u0/(4*pi))*(((((-1)^1*d1)/(r1*(r1+((-1)^(1+1))*C1)))-(C1/(r1*(r1+d1))))+((((-1)^2*d2)/(r2*(r2+((-1)^(2+1))*C2)))-(C2/(r2*(r2+d2))))+((((-1)^3*d3)/(r3*(r3+((-1)^(3+1))*C3)))-(C3/(r3*(r3+d3))))+((((-1)^4*d4)/(r4*(r4+((-1)^(4+1))*C4)))-(C4/(r4*(r4+d4)))))
When it reaches the sub-expression (-1)^1*d1 then it encounters a reference to d1, which is the handle to an anonymous function. d1 is after an * operator, so you are trying to multiply something by the anonymous function d1. Your code is not a request to execute d1 with some argument and multiply based upon the return value: it is a request to multiply the anonymous function itself. Which is not defined.
MATLAB will not look at the d1 and see that it was defined in terms of dummy argumented aj and so try to look to see if there is an active variable named aj that it should use as the argument for executing d1 .
Dummy argument names to an anonymous function are effectively in their own namespace, as if you had written something like.
function Q93277CEA4_result = Q93277CEA4(aj_of_function_Q93277CEA4)
Q93277CEA4_result = y + aj_of_function_Q93277CEA4
end
d1 = @Q93277CEA4
and
function N76783_result = N76783(ai_of_function_N76783, aj_of_function_N76783)
N76783_result = (u0/(4*pi))*(((((-1)^1*d1)/(r1*(r1+((-1)^(1+1))*C1)))-(C1/(r1*(r1+d1))))+((((-1)^2*d2)/(r2*(r2+((-1)^(2+1))*C2)))-(C2/(r2*(r2+d2))))+((((-1)^3*d3)/(r3*(r3+((-1)^(3+1))*C3)))-(C3/(r3*(r3+d3))))+((((-1)^4*d4)/(r4*(r4+((-1)^(4+1))*C4)))-(C4/(r4*(r4+d4)))))
end
Bz = @N76783
Under no circumstances will N76783 associate aj_of_function_N76783 with aj_of_function_Q93277CEA4 by itself.
IF you want d1 to be invoked with a particular argument in Bz, then you need to say so specifically, like
Bz= @(ai,aj) (u0/(4*pi))*(((((-1)^1*d1(aj))/(r1(ai,aj)*(r1(ai,aj)+((-1)^(1+1))*C1(ai)))) and so on
  9 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by