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 Center および File ExchangeGraphics Performance についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by