How do I perform this integration?

1 view (last 30 days)
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);

Accepted Answer

Torsten
Torsten on 3 Mar 2015
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.
  1 Comment
Dipankar Narayanan
Dipankar Narayanan on 3 Mar 2015
Dear @Torsten, Thanks for your answer. Its a sample of my problem. The real problem is even bigger. The vectors are of length 400. Doing it with pencil and paper is really troublesome. Cannot I do it in matlab?

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!