Results 1 to 5 of 5

Math Help - Need help setting up this integral in MATLAB

  1. #1
    Member
    Joined
    Jun 2012
    From
    Georgia
    Posts
    175
    Thanks
    22

    Need help setting up this integral in MATLAB

    I'm trying to code

    -\int_{-\pi}^0 \frac{1}{n}sin(nx)\ dx + \int_0^{\pi} \frac{1}{n}sin(nx)\ dx

    in Matlab. I am using the following: - 1/n*integral(sin(n*x),x,-pi,0) + 1/n*integral(sin(n*x),x,0,pi)

    But this is what Matlab thinks I'm putting in:

    Why on earth is the first integral messed up but not the second?? And how do I fix the first one?


    EDIT: Fixed it. I just needed to add parentheses--i.e., (- 1/n*integral(sin(n*x),x,-pi,0)) + (1/n*integral(sin(n*x),x,0,pi)). But why does this work and the original way doesn't?
    Last edited by phys251; October 6th 2012 at 03:32 PM.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Junior Member MathTutor2013's Avatar
    Joined
    Oct 2012
    From
    usa
    Posts
    25
    Thanks
    6

    Re: Need help setting up this integral in MATLAB

    Hi,

    You do not need a program to find it

    primitve of (1/n)sin(nx) Is equal to: -(1/n^2)cos(nx)

    then te second integral is: -(1/n^2)[cos(n(pi))-cos(0)]

    = -1/n^2 if n is even

    = 1/n^2 if n is odd

    The first integral is eqal to the second one
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Member
    Joined
    Jun 2012
    From
    Georgia
    Posts
    175
    Thanks
    22

    Re: Need help setting up this integral in MATLAB

    I know that; it's a rather easy integral to evaluate. But it's part of a larger function I'm trying to set up, and this is the part I'm messing up on.
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Junior Member MathTutor2013's Avatar
    Joined
    Oct 2012
    From
    usa
    Posts
    25
    Thanks
    6

    Re: Need help setting up this integral in MATLAB

    Try to put the fractions 1/n between ()

    (1/n)*.....
    (-1/n) *.....
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Member
    Joined
    Jun 2012
    From
    Georgia
    Posts
    175
    Thanks
    22

    Re: Need help setting up this integral in MATLAB

    OK thanks.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Setting up a Matlab web server
    Posted in the Math Software Forum
    Replies: 0
    Last Post: April 30th 2010, 02:47 PM
  2. Need help setting this integral.
    Posted in the Calculus Forum
    Replies: 1
    Last Post: April 28th 2010, 10:27 AM
  3. Setting up an abs. value integral
    Posted in the Calculus Forum
    Replies: 1
    Last Post: September 26th 2009, 01:18 PM
  4. NEED HELP SETTING UP INTEGRAL!!
    Posted in the Calculus Forum
    Replies: 1
    Last Post: November 13th 2008, 11:08 PM
  5. Setting Up Integral
    Posted in the Calculus Forum
    Replies: 1
    Last Post: October 21st 2008, 06:27 PM

Search Tags


/mathhelpforum @mathhelpforum