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

1 view (last 30 days)
for d=0.1:0.1:1
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]
hold on
ERROR: Undefined operator '*' for input arguments of type 'function_handle'.
Error in FPSSConlyM3 (line 62)

Accepted Answer

Walter Roberson
Walter Roberson on 14 Aug 2019
You have
d1=@(aj) y+aj
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
d1 = @Q93277CEA4
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)))))
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

Sign in to comment.

More Answers (0)


Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!