Need help setting up this integral in MATLAB

I'm trying to code

+

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: http://www4a.wolframalpha.com/Calcul...=48&w=328&h=37

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?

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

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.

Re: Need help setting up this integral in MATLAB

Try to put the fractions 1/n between ()

(1/n)*.....

(-1/n) *.....

Re: Need help setting up this integral in MATLAB