Kindly help me integrate this function.

조회 수: 1 (최근 30일)
Furqan Haider
Furqan Haider 2014년 5월 11일
댓글: Star Strider 2014년 5월 11일
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.

채택된 답변

Star Strider
Star Strider 2014년 5월 11일
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
Furqan Haider
Furqan Haider 2014년 5월 11일
Thank u again, I got what was required.
Best regards.
Star Strider
Star Strider 2014년 5월 11일
My pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by