Results 1 to 4 of 4

Math Help - URGENT: MATLAB quad function frustration

  1. #1
    Junior Member
    Joined
    May 2008
    Posts
    50

    URGENT: MATLAB quad function frustration

    Hi all,

    I'm trying to use the built-in MATLAB function quad to integrate the following function :


     \int_{0}^{2\pi}\ x * sin (x) \ dx but its not working for me.

    Now when I use the quad function to evaluate

     \int_{0}^{2\pi}\ x \ dx I get the correct answer.

    When I use the quad function to evaluate

     \int_{0}^{2\pi}\ sin (x) \ dx I get the correct answer.

    but when I use the quad function to evaluate

     \int_{0}^{2\pi}\ x * sin (x) \ dx

    I get the output

    ??? Error using ==> mtimes
    Inner matrix dimensions must agree.

    Error in ==> myfun at 7
    y = sin(x) * x ;

    Error in ==> quad at 77
    y = f(x, varargin{:});

    where myfun is the mfile I wrote .........

    function y = myfun(x)
    y = sin(x) * x ;


    Also this is what I type into the MATLAB command window when I try and use the quad function

    Q = quad(@myfun,0,(2*pi))


    What am I doing wrong here? Im no expert in MATLAB and Im not sure how to get around this.
    Last edited by woody198403; September 3rd 2008 at 07:06 PM.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Junior Member
    Joined
    May 2008
    Posts
    50
    Nevermind, I realised that I had to vectorize my mfile by changing it to

    function y = myfun(x)
    y = x.*sin(x);


    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    May 2009
    Posts
    12
    Quote Originally Posted by woody198403 View Post
    Hi all,

    I'm trying to use the built-in MATLAB function quad to integrate the following function :


     \int_{0}^{2\pi}\ x * sin (x) \ dx but its not working for me.

    Now when I use the quad function to evaluate

     \int_{0}^{2\pi}\ x \ dx I get the correct answer.

    When I use the quad function to evaluate

     \int_{0}^{2\pi}\ sin (x) \ dx I get the correct answer.

    but when I use the quad function to evaluate

     \int_{0}^{2\pi}\ x * sin (x) \ dx

    I get the output

    ??? Error using ==> mtimes
    Inner matrix dimensions must agree.

    Error in ==> myfun at 7
    y = sin(x) * x ;

    Error in ==> quad at 77
    y = f(x, varargin{:});

    where myfun is the mfile I wrote .........

    function y = myfun(x)
    y = sin(x) * x ;


    Also this is what I type into the MATLAB command window when I try and use the quad function

    Q = quad(@myfun,0,(2*pi))


    What am I doing wrong here? Im no expert in MATLAB and Im not sure how to get around this.
    u need to put dot before multiplication sign(array)...try this
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by woody198403 View Post
    Hi all,

    I'm trying to use the built-in MATLAB function quad to integrate the following function :


     \int_{0}^{2\pi}\ x * sin (x) \ dx but its not working for me.

    Now when I use the quad function to evaluate

     \int_{0}^{2\pi}\ x \ dx I get the correct answer.

    When I use the quad function to evaluate

     \int_{0}^{2\pi}\ sin (x) \ dx I get the correct answer.

    but when I use the quad function to evaluate

     \int_{0}^{2\pi}\ x * sin (x) \ dx

    I get the output

    ??? Error using ==> mtimes
    Inner matrix dimensions must agree.

    Error in ==> myfun at 7
    y = sin(x) * x ;

    Error in ==> quad at 77
    y = f(x, varargin{:});

    where myfun is the mfile I wrote .........

    function y = myfun(x)
    y = sin(x) * x ;


    Also this is what I type into the MATLAB command window when I try and use the quad function

    Q = quad(@myfun,0,(2*pi))


    What am I doing wrong here? Im no expert in MATLAB and Im not sure how to get around this.
    function y = myfun(x)
    y = sin(x) .* x ;

    CB
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Replies: 11
    Last Post: February 21st 2011, 09:35 AM
  2. Replies: 5
    Last Post: March 22nd 2010, 10:36 PM
  3. Matlab help~~urgent
    Posted in the Math Software Forum
    Replies: 3
    Last Post: November 10th 2009, 03:47 PM
  4. Urgent Matlab
    Posted in the Math Software Forum
    Replies: 3
    Last Post: April 10th 2008, 01:01 PM
  5. Graph each quad. function help
    Posted in the Pre-Calculus Forum
    Replies: 2
    Last Post: October 31st 2007, 08:09 PM

Search Tags


/mathhelpforum @mathhelpforum