Application Center - Maplesoft

App Preview:

Integrals in Maple

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

Learn about Maple
Download Application


 

Image 

 

 

> # 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;
 

proc (t) options operator, arrow; `+`(3, `*`(`^`(t, 2))) end proc (1)
 

> # The area under the curve is given by
 

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

>
 

Int(`+`(3, `*`(`^`(t, 2))), t = 0 .. 4) (2)
 

> evalf(%);
 

33.33333333 (3)
 

>
 

>
 

>
 

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

>
 

> restart;
 

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

>
 

proc (t) options operator, arrow; `+`(3, `*`(`^`(t, 2))) end proc (4)
 

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

>
 

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

Plot_2d
 

>
 

> 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);
 

>
 

Plot_2d
 

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

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

 

 

 

4
7
12
19 (5)
 

> # In order to get the area of each rectangles
 

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

>
 

> f(1)*1;
 

4 (6)
 

> f(2)*1;
 

7 (7)
 

> f(3)*1;
 

12 (8)
 

> f(4)*1;
 

19 (9)
 

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

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

[4, 7, 12, 19] (10)
 

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

42. (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;
 

proc (t) options operator, arrow; `+`(3, `*`(`^`(t, 2))) end proc (12)
 

> # The total amount of triangles
 

> Q:=40;
 

40 (13)
 

> # The amount of triangles between 0 and 1
 

> P:=Q/4;
 

10 (14)
 

> # The incremental change in t over time
 

> T:=evalf(1/P);
 

.1000000000 (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);
 

Plot_2d
 

> # 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);
 

 

 

 

3.010000000
3.040000000
3.090000000
3.160000000 (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;
 

.3010000000 (17)
 

> f(T+T)*T;
 

.3040000000 (18)
 

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

.3090000000 (19)
 

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

.3160000000 (20)
 

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

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

[.301, .304, .309, .316, .325, .336, .349, .364, .381, .400, .421, .444, .469, .496, .525, .556, .589, .624, .661, .700, .741, .784, .829, .876, .925, .976, 1.03, 1.08, 1.14, 1.20, 1.26, 1.32, 1.39, 1...
[.301, .304, .309, .316, .325, .336, .349, .364, .381, .400, .421, .444, .469, .496, .525, .556, .589, .624, .661, .700, .741, .784, .829, .876, .925, .976, 1.03, 1.08, 1.14, 1.20, 1.26, 1.32, 1.39, 1...
[.301, .304, .309, .316, .325, .336, .349, .364, .381, .400, .421, .444, .469, .496, .525, .556, .589, .624, .661, .700, .741, .784, .829, .876, .925, .976, 1.03, 1.08, 1.14, 1.20, 1.26, 1.32, 1.39, 1...
(21)
 

> nops(S);
 

40 (22)
 

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

34.1 (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;
 

proc (t) options operator, arrow; `+`(`*`(`^`(t, 2)), 3) end proc (24)
 

 

> # The total amount of triangles
 

> Q:=24;
 

24 (25)
 

> # The amount of triangles between 0 and 1
 

> P:=Q/4;
 

6 (26)
 

> # The incremental change in t over time
 

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

.1667 (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);
 

>
 

Plot_2d
 

>
 

>
 

> # 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);
 

 

 

 

 

3.02778889
3.11115556
3.25010001
3.44462224
3.69472225 (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;
 

`+`(`*`(`/`(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);
 

`+`(`*`(`/`(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), `*...
`+`(`*`(`/`(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), `*...
(30)
 

> T_:=collect(%,triangle_t);
 

`*`(`+`(`*`(`/`(1, 2), `*`(H_(0))), `*`(`/`(1, 2), `*`(H_(1))), `*`(`/`(1, 2), `*`(H(1))), `*`(`/`(1, 2), `*`(H_(2))), `*`(`/`(1, 2), `*`(H(2))), `*`(`/`(1, 2), `*`(H(3)))), `*`(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_;
 

`*`(`+`(`*`(`/`(1, 2), `*`(H_(0))), H(1), H(2), `*`(`/`(1, 2), `*`(H(3)))), `*`(triangle_t)) (32)
 

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

>
 

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

>
 

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

.505 (33)
 

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

.515 (34)
 

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

.530 (35)
 

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

.560 (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)];
 

[.505, .515, .530, .560, .595, .640, .700, .760, .835, .920, 1.01, 1.12, 1.22, 1.34, 1.48, 1.62, 1.76, 1.92, 2.09, 2.26, 2.44, 2.64, 2.84, 3.06]
[.505, .515, .530, .560, .595, .640, .700, .760, .835, .920, 1.01, 1.12, 1.22, 1.34, 1.48, 1.62, 1.76, 1.92, 2.09, 2.26, 2.44, 2.64, 2.84, 3.06]
(37)
 

>
 

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

33.360 (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;
 

proc (t) options operator, arrow; `+`(A, B, `*`(`+`(W, E), `*`(t))) end proc (39)
 

 

> # The area under the curve is therefore given by
 

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

>
 

Int(`+`(A, B, `*`(`+`(W, E), `*`(t))), t = 0 .. 4) (40)
 

> # Our parameteres are given by
 

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

Int(`+`(15, `*`(10, `*`(t))), t = 0 .. 4) (41)
 

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

> evalf(I_);
 

140. (42)
 

>
 

> with(student):
 

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

Plot_2d
 

>
 

>
 

 

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.