Question: Plot the integral of a discrete function

restart; N := 100; dx := evalf(2*Pi/N)

100

 

0.6283185308e-1

(1)

f1 := proc (x) options operator, arrow; sin(x) end proc;

proc (x) options operator, arrow; sin(x) end proc

(2)

DiscX := proc (N, dx) local i, xv; xv := Vector(N); for i to N do xv[i] := evalf((i-(1/2)*N-1)*dx) end do; return xv end proc:

Xfun := proc (f1) local i, xa1, xa2; xa1 := Vector(N); xa2 := Vector(N); for i to N do xa1[i] := evalf(subs(x = a[i], f1(x))) end do; return xa1 end proc:

IntNum := proc (N, a, c) local i, xv1; xv1 := Vector(N); for i from 2 to N-1 do xv1[i] := evalf((1/2)*(a[i]-a[i+1])*(c[i]+c[i+1])) end do; return xv1 end proc:

a := DiscX(N, dx); a[1]; a[100]

a := Vector(4, {(1) = ` 1 .. 100 `*Vector[column], (2) = `Data Type: `*anything, (3) = `Storage: `*rectangular, (4) = `Order: `*Fortran_order})

 

-3.141592654

 

3.078760801

(3)

c := Xfun(f1); c[1]

c := Vector(4, {(1) = ` 1 .. 100 `*Vector[column], (2) = `Data Type: `*anything, (3) = `Storage: `*rectangular, (4) = `Order: `*Fortran_order})

 

0.4102067615e-9

(4)

k := IntNum(N, a, c)

k := Vector(4, {(1) = ` 1 .. 100 `*Vector[column], (2) = `Data Type: `*anything, (3) = `Storage: `*rectangular, (4) = `Order: `*Fortran_order})

(5)

plot([seq([a[i], k[i]], i = 2 .. N)], style = line, title = typeset("Integ_of_sin(x)"), titlefont = [times, bold, 30]);

 

``

Download test.mw

Hey everyone!

I would like to plot the integral of a discrete function. For simplicity, I choose the function sin(x) between –Pi and Pi, which has as an integral -cos(x). I tried to implement that in Maple using the Trapezoidal rule, but the result is simply wrong. Any help would be much appreciated!

Please Wait...