Kindly help me integrate this function.

1 Ansicht (letzte 30 Tage)
Furqan Haider
Furqan Haider am 11 Mai 2014
Kommentiert: Star Strider am 11 Mai 2014
I am trying to integrate the following expression using 'quad' fuction but MATLAB is giving errors, kindly help me with the code. Code starts below:
f= @(x) ((sin(x))^2)/(((sin(x))^2)+(7));
% a, the lower limit
a= 0 ;
% b, the upper limit
b= pi/2 ;
answer=quad(f,a,b);
%%% Code ends
MATLAB gives following error:
??? Error using ==> mpower Inputs must be a scalar and a square matrix.
Error in ==> @(theta)((sin(theta))^2)/(((sin(theta))^2)+(7))
Error in ==> quad at 77 y = f(x, varargin{:});
Kindly help.

Akzeptierte Antwort

Star Strider
Star Strider am 11 Mai 2014
You need to vectorize your code.
This works:
f= @(x) ((sin(x)).^2)./(((sin(x)).^2)+(7));
a= 0 ;
b= pi/2 ;
answer=quad(f,a,b);
produces:
answer =
101.4509e-003
  4 Kommentare
Furqan Haider
Furqan Haider am 11 Mai 2014
Thank u again, I got what was required.
Best regards.
Star Strider
Star Strider am 11 Mai 2014
My pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Performance finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by