Parameter vectors outside integration function

I am trying to calculate a double integral with three varibales in the form of a vector AB and another scalar B also as a paremeter. If I write the routine so that AB and B are inside the integration fucntion:
Inty3=integral2(@Func3,0,1,0,@(y) y)
function fy3 = Func3(z,y)
AB=[1 2 3];
BB=1;
fy0=sqrt((AB(1)*z+AB(2)).^2+(BB*z+AB(3)).^2);
fyy=((1+fy0).^2)./(1-fy0); % F(y) in Eq.17
fAy=(AB(1)*z+AB(2))./(1-fy0);
fy3=fyy.*fAy;
end
the integral is clauclated without a problem, but if AB and B are moved outside of Fun3, i.e.,
AB=[1 2 3];
BB=1;
Inty3=integral2(@Func3,0,1,0,@(y) y)
function fy3 = Func3(z,y)
fy0=sqrt((AB(1)*z+AB(2)).^2+(BB*z+AB(3)).^2);
fyy=((1+fy0).^2)./(1-fy0); % F(y) in Eq.17
fAy=(AB(1)*z+AB(2))./(1-fy0);
fy3=fyy.*fAy;
end
then I receive the following error message:
Not enough input arguments.
Error in DoubleInt>Func3 (line 15)
fy0=sqrt((AB(1)*z+AB(2)).^2+(BB*z+AB(3)).^2);
Error in integral2Calc>integral2t/tensor (line 228)
Z = FUN(X,Y); NFE = NFE + 1;
Error in integral2Calc>integral2t (line 55)
[Qsub,esub] = tensor(thetaL,thetaR,phiB,phiT);
Error in integral2Calc (line 9)
[q,errbnd] =
integral2t(fun,xmin,xmax,ymin,ymax,optionstruct);
Error in integral2 (line 106)
Q = integral2Calc(fun,xmin,xmax,yminfun,ymaxfun,opstruct);
Error in DoubleInt (line 10)
Inty3=integral2(@Func3,0,1,0,@(y) y)

 Accepted Answer

You need to change your call to ‘Func3’ in the second example:
Inty3=integral2(@(z,y) Func3(z,y,BB,AB),0,1,0,@(y) y)

4 Comments

Saeid
Saeid on 30 Apr 2017
Edited: Saeid on 30 Apr 2017
I tried it and it didn't work :-( Did you try that exact same format yourself with my program?
Try this and it will :-)
AB=[1 2 3];
BB=1;
Inty3=integral2(@(z,y) Func3(z,y,AB,BB),0,1,0,@(y)y)
function fy3 = Func3(z,y,AB,BB)
fy0=sqrt((AB(1)*z+AB(2)).^2+(BB*z+AB(3)).^2);
fyy=((1+fy0).^2)./(1-fy0); % F(y) in Eq.17
fAy=(AB(1)*z+AB(2))./(1-fy0);
fy3=fyy.*fAy;
end
Inty3 =
3.2745
Perfect, thanks!

Sign in to comment.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Asked:

on 30 Apr 2017

Commented:

on 30 Apr 2017

Community Treasure Hunt

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

Start Hunting!