Application Center - Maplesoft

# Integrals in Maple

You can switch back to the summary page by clicking here.

 > # Integrals in Maple

 >

 >

 > The following was implemented in Maple by Marcus Davidsson (2008) davidsson_marcus@hotmail.com

 >

 >

 >

 >

 > ############################# Our basic Integral ############################

 > restart;

 > # Our curve is given by

 > f:= t -> 3+t^2;

 (1)

 > # The area under the curve is given by

 > Int(f(t),t=0..4);

 >

 (2)

 > evalf(%);

 (3)

 >

 >

 >

 > ############################ Summation when rectangule width is 1  ######################

 >

 > restart;

 > f:= t -> 3+t^2;

 >

 (4)

 > # Note that the intercept is 3 and the slope is 1

 >

 > plot(f(t), t = 0..4, color = blue);

 >

 > with(student):

 > # The last 4 in the maple input below is the number of rectangles in the below figure

 > rightbox(f(t), t = 0..4, 4, color = blue, shading = grey);

 >

 > # The value of f (height) at different time periods are given by

 > f(1);f(2);f(3);f(4);

 (5)

 > # In order to get the area of each rectangles

 > # we multiply the height with the width (=1)

 >

 > f(1)*1;

 (6)

 > f(2)*1;

 (7)

 > f(3)*1;

 (8)

 > f(4)*1;

 (9)

 > # The total area is simply the sum of the individual retangles

 > S:=[seq(f(i)*1,i=1..4,1)];

 (10)

 > evalf(sum(S[k]*1,k=1..4),3);

 (11)

 >

 > # Our integral was 33.3 so it is a bit over. We can increase the accuracy

 > # by decreasing the rectangule width

 >

 >

 >

 >

 > ######################## Summation when rectangule width is 1/10  #############

 >

 > restart;

 > f:= t -> 3+t^2;

 (12)

 > # The total amount of triangles

 > Q:=40;

 (13)

 > # The amount of triangles between 0 and 1

 > P:=Q/4;

 (14)

 > # The incremental change in t over time

 > T:=evalf(1/P);

 (15)

 > with(student):

 > # The Q in the maple input below is the number of rectangles in the below figure

 > rightbox(f(t), t = 0..4, Q, color = blue, shading = grey);

 > # The value of f (height) for the first 4 cases are given by

 > f(T);f(T+T);f(T+T+T);f(T+T+T+T);

 (16)

 > # In order to get the area of each rectangles

 > # we multiply the hight with the width T. So for the first 4 cases we get

 >

 > f(T)*T;

 (17)

 > f(T+T)*T;

 (18)

 > f(T+T+T)*T;

 (19)

 > f(T+T+T+T)*T;

 (20)

 > # The total area is simply the sum of the individual retangles

 > S:=[evalf(seq(f(i)*T,i=T..4.01,T),3)];

 (21)

 > nops(S);

 (22)

 > evalf(sum(S[k]*1,k=1..nops(S)),3);

 (23)

 >

 > # Our integral was 33.3 so we are still a little bit over.

 > # we will now increase the accuratcy by using the Trapozide rule

 >

 >

 >

 >

 > ################################  Trapozide Rule  ##############################

 > restart;

 > f:= t -> t^2 + 3;

 (24)

 > # The total amount of triangles

 > Q:=24;

 (25)

 > # The amount of triangles between 0 and 1

 > P:=Q/4;

 (26)

 > # The incremental change in t over time

 > T:=evalf(1/P,4);

 (27)

 > with(student):

 > # The Q in the maple input below is the number of rectangles in the below figure

 > leftbox(f(t), t = 0..4, Q, color = blue, shading = grey);

 >

 >

 >

 > # The value of f (height) at different time periods is given by

 > f(T);f(T+T);f(T+T+T);f(T+T+T+T);f(T+T+T+T+T);

 (28)

 >

 > # We have previously just took the height of the rectangle at time t which meant that

 > # we overestimated the height of the rectangel. In this case in order

 > # to get the area of each rectangles we use the trapezoid rule.

 > # We approximate the hight of each rectangle by taking the value of f

 > # at time t (height at time t) plus the value of f at time t+1 (height at time t+1)

 > # divided by 2 (average height). We then multiply that average height with the

 > # rectangle width. Note that the trapezoid rule results in that we over estimate

 > # the area to the left of the curve and underestimate the area to the right

 > # of the curve, which means that the rectagual area should be more accurate.

 >

 >

 > #################################################

 >

 > # Trapezoid rule for a three period curve

 >

 > T_:=(1/2)*[H(0)+H(1)]*triangle_t+(1/2)*[H(1)+H(2)]*triangle_t+(1/2)*[H(2)+H(3)]*triangle_t;

 (29)

 > # If we multiply in (1/2) and triangle_t in the parenthases and notice that

 > # H(0)=H_(0),H(1)=H_(1) and H(2)=H_(2) we get;

 >

 > T_:=(1/2)*triangle_t*H_(0)+(1/2)*triangle_t*H_(1)+(1/2)*triangle_t*H(1)+(1/2)*triangle_t*H_(2)+(1/2)*triangle_t*H(2)+(1/2)*triangle_t*H(3);

 (30)

 > T_:=collect(%,triangle_t);

 (31)

 > # we note that (1/2)*H_(1)+(1/2)*H(1)=H(1) and (1/2)*H_(2)+(1/2)*H(2)=H(2) so we get

 > H_(1):=H(1): H_(2):=H(2): T_;

 (32)

 > #################################################

 >

 > # The rectanguel width is T so for the first 4 cases we get

 >

 > evalf(((f(0)+f(T))/2)*T,3);

 (33)

 > evalf(((f(T)+f(T+T))/2)*T,3);

 (34)

 > evalf(((f(T+T)+f(T+T+T))/2)*T,3);

 (35)

 > evalf(((f(T+T+T)+f(T+T+T+T))/2)*T,3);

 (36)

 > # As previously the total area is simply the sum of the individual retangles

 >

 > # We can also solve the above problem by typing

 > for i from T by T to 4.01 do

 > A[i]:=evalf(((f(i-T)+f(i))/2)*T,3) end do:

 > S:=[seq(A[i],i=T..4.01,T)];

 (37)

 >

 > sum(S[j],j=1..Q);

 (38)

 >

 > # Our integral was 33.3 so 33.36 is acceptable. However to get the most

 > # accurate estimation of the area under the curve we should use the integral

 >

 >

 >

 > #######################  Basic Economics Example and Extention ####################

 >

 > restart;

 > # The growth of an economy G evolves over time and is a function of 5 variables

 > # Initial resources A (influence the intercept )

 > # Initial population B (influence the intercept )

 > # Peoples willingness to work W (influence slope)

 > # Amount of entreprenesurieal activities E (influence slope)

 > # Time (slope)

 >

 > # The larger the area under the curve G(t) the larger the growth in the economy

 >

 > # Our curve is given by

 > G:= t -> (A+B)+(W+E)*t;

 (39)

 > # The area under the curve is therefore given by

 > I_:=Int(G(t),t=0..4);

 >

 (40)

 > # Our parameteres are given by

 > A:=5: B:=10: W:=5: E:=5: I_;

 (41)

 > # The gowth in the economy is there for given by

 > evalf(I_);

 (42)

 >

 > with(student):

 > leftbox(G(t), t = 0..4, 10, color = blue, shading = grey);

 >

 >

Legal Notice: The copyright for this application is owned by the authors. Neither Maplesoft nor the authors are responsible for any errors contained within and are not liable for any damages resulting from the use of this material.. This application is intended for non-commercial, non-profit use only. Contact the authors for permission if you wish to use this application in for-profit activities.