MATLAB: How to perform this integration

numerical integration

H=[11 22 33 44 55 66];
R=[1 2 3 4 5];
f_low=[1000 3000 5000 7000 9000];
f_high=[2000 4000 6000 8000 10000];
Const=5;
RESULTS=[];
for i=1:length(H)
val=quadgk(@(f)MyFunction(f,H,R,Const),f_low(i),f_high(i));
RESULTS=[RESULTS val];
end
+++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++
function int_out=MyFunction(f,H,R,Const)
AAA=Const+2.*sum(H.*cos(2*pi*f*R));
int_out=AAA.^2;
+++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++
I get the following Error:
Error using * Inner matrix dimensions must agree.
Error in MyFunction (line 3) AAA=Const+2.*sum(H.*cos(2*pi*f*R));
Error in @(f)MyFunction(f,H,R,Const)
Error in quadgk/evalFun (line 330) fx = FUN(x);
Error in quadgk/f1 (line 348) [y,too_close] = evalFun(tt);
Error in quadgk/vadapt (line 249) [fx,too_close] = f(x);
Error in quadgk (line 188) [q,errbnd] = vadapt(@f1,interval);

Best Answer

  • I'd do the integration by taking pencil and paper:
    The antiderivative of a*cos(2*pi*x*R) is a/(2*pi*R)*sin(2*pi*x*R).
    Best wishes
    Torsten.