From: kk wu on
I came across some problems with quad (or quadgk) while performing a numerical integral.

I defined a matlab function F(x,d,dhat,y) and I want to see the integral of this F function as a function of d (other variables are considered to be constants).

When I perform the integral (quad(@(d)(2-myiso1st(.7, d, .4, .4)),.4,dstar);) some warning message appears. Could anyone tell me how quad and quadgk works? And how to solve my problem. (I'm fresh in using MATLAB :p)

----------------------------------------------------------------------------------------
??? Error using ==> mtimes
Inner matrix dimensions must agree.

Error in ==> myiso1st at 7
isoa=r*((isod-isox)*normcdf((isox-isod)/sigma)-(sigma/sqrt(2*pi))*exp(-(isox-isod)^2/(2*sigma^2))-(isodh-isox)*normcdf((isox-isodh)/sigma)+(sigma/sqrt(2*pi))*exp(-(isox-isodh)^2/(2*sigma^2)))/(r*isoy
Error in ==> @(d)(2-myiso1st(.7,d,.4,.4))


Error in ==> quad at 77
y = f(x, varargin{:});
----------------------------------------------------------------------------------------------


The F function is attached bellow.
----------------------------------------------------------------------------------------------
function [ isoa ] = F(isox, isod, isodh, isoy )
%MYISO1ST Summary of this function goes here
% Detailed explanation goes here
% a=(rE(x,d)-rE(x,dhat))/(ryE(x,dhat)-y^2/2);
r=1.5;
sigma=.1;
isoa=r*((isod-isox)*normcdf((isox-isod)/sigma)-(sigma/sqrt(2*pi))*exp(-(isox-isod)^2/(2*sigma^2))-(isodh-isox)*normcdf((isox-isodh)/sigma)+(sigma/sqrt(2*pi))*exp(-(isox-isodh)^2/(2*sigma^2)))/(r*isoy*((isodh-isox)*normcdf((isox-isodh)/sigma)+isox-(sigma/sqrt(2*pi))*exp(-(isox-isodh)^2/(2*sigma^2)))-isoy^2/2);
end

--------------------------------------------------------------------------------------------
From: John D'Errico on
"kk wu" <wukekun(a)gmail.com> wrote in message <hoprt1$d4r$1(a)fred.mathworks.com>...
> I came across some problems with quad (or quadgk) while performing a numerical integral.
>
> I defined a matlab function F(x,d,dhat,y) and I want to see the integral of this F function as a function of d (other variables are considered to be constants).
>
> When I perform the integral (quad(@(d)(2-myiso1st(.7, d, .4, .4)),.4,dstar);) some warning message appears. Could anyone tell me how quad and quadgk works? And how to solve my problem. (I'm fresh in using MATLAB :p)
>
> ----------------------------------------------------------------------------------------
> ??? Error using ==> mtimes
> Inner matrix dimensions must agree.
>
> Error in ==> myiso1st at 7
> isoa=r*((isod-isox)*normcdf((isox-isod)/sigma)-(sigma/sqrt(2*pi))*exp(-(isox-isod)^2/(2*sigma^2))-(isodh-isox)*normcdf((isox-isodh)/sigma)+(sigma/sqrt(2*pi))*exp(-(isox-isodh)^2/(2*sigma^2)))/(r*isoy
> Error in ==> @(d)(2-myiso1st(.7,d,.4,.4))

You need to understand the difference between
the * and .* operators in matlab. quad and quadgk
will call your function at multiple values at once.
So you needed to use .* everywhere there.

help mtimes
help times

John