??? Index exceeds matrix dimensions.

1 view (last 30 days)
MinHyung
MinHyung on 20 Aug 2013
I tried to use function 'quad' but failed...
>> quad (@(phi) (224 - 32*sin(7) + 32*cos((7.*cos(phi))./2).^2.*sin(7) + 32*cos((7.*sin(phi))./2).^2.*sin(7) - 224*cos((7*cos(phi))./2).^2 - 224*cos((7*sin(phi))./2).^2 - 32*cos((7*cos(phi))./2).^2.*cos((7*sin(phi))./2).^2.*sin(7) + 224*cos((7*cos(phi))./2).^2.*cos((7*sin(phi))./2).^2)/(823543.*cos(phi).^2 - 823543*cos(phi).^4), 0.1,pi/2-0.1)
??? Index exceeds matrix dimensions.
Error in ==> quad at 85
if ~isfinite(y(7))
--------------------------------------------------------------------
'quad' with separate part works well
this part :
(224 - 32*sin(7) + 32*cos((7.*cos(phi))./2).^2.*sin(7) + 32*cos((7.*sin(phi))./2).^2.*sin(7) - 224*cos((7*cos(phi))./2).^2 - 224*cos((7*sin(phi))./2).^2 - 32*cos((7*cos(phi))./2).^2.*cos((7*sin(phi))./2).^2.*sin(7) + 224*cos((7*cos(phi))./2).^2.*cos((7*sin(phi))./2).^2)
and this part :
(823543.*cos(phi).^2 - 823543*cos(phi).^4
Is there anyone who knows this reason?
Thank you very much in advance.

Answers (1)

the cyclist
the cyclist on 20 Aug 2013
Edited: the cyclist on 20 Aug 2013
Do you get what you expect if you use "./" instead of just "/" for the division of your two terms?
This code works for me:
f1 = @(phi) (823543.*cos(phi).^2 - 823543*cos(phi).^4);
f2 = @(phi) (224 - 32*sin(7) + 32*cos((7.*cos(phi))./2).^2.*sin(7) + 32*cos((7.*sin(phi))./2).^2.*sin(7) - 224*cos((7*cos(phi))./2).^2 - 224*cos((7*sin(phi))./2).^2 - 32*cos((7*cos(phi))./2).^2.*cos((7*sin(phi))./2).^2.*sin(7) + 224*cos((7*cos(phi))./2).^2.*cos((7*sin(phi))./2).^2);
f3 = @(phi) f2(phi)./f1(phi);
quad(f3,0.1,pi/2-0.1)
  2 Comments
MinHyung
MinHyung on 20 Aug 2013
Thank you very much! This problem consume my time a lot ㅠㅠ
the cyclist
the cyclist on 20 Aug 2013
I would appreciate it if you "accept" the answer, which may also help someone in the future who seeks a similar solution.

Sign in to comment.

Categories

Find more on MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!