You are here

Example 6.3

12 October, 2015 - 14:01

Determine the value of the following integral:

\int _0^\pi sin(x)dx

  1. Initialize variable x as a row vector, from 0 with increments of pi/100 to pi:
  2. x=0:pi/100:pi;
  3. Declare variable y as y=sin(x);
  4. Issue the following command to calculate the first area, the output will be as follows:
    area1=trapz(x,y)
area1 =
    1.9998

let us increase the increments as above:

    x=0:pi/1000:pi;
y=sin(x);
area2=trapz(x,y)

area2 =

    2.0000