You are on page 1of 14

VIETNAM NATIONAL UNIVERSITY

HO CHI MINH CITY UNIVERSITY OF TECHNOLOGY


Ho Chi Minh city, December 2019

CALCULUS 1
MATLAB PROJECT
Class: CC09

Group members:
Phạm Văn Minh Toàn 1953028
Hoàng Thắng 1952992
Dương Ngọc Trúc Uyên 1953091
Trương Ngọc Kim Ngân 1952351
Nguyễn Ngọc Lam 1952807
Phạm Thảo Nhiên 1952904
Lê Nguyễn Khánh Trúc 1953056
HO CHI MINH CITY UNIVERSITY OF TECHNOLOGY

1. Theorem
1.1. Derivatives
The derivative of a function f at a number a, denoted by f’(a) is
( ) ( )
( )

If this limit exists

Other notation: f’(a) = y’(a) = | = ( )

If we write , then we have and approaches if and


only if approaches . Therefore an equivalent way of stating the definition
of the derivative:

( ) ( )
( )

1.2. Definite Integral


a) If is a function defined for we divide the interval into n
subintervals of equal width ( ) . We let
( ) ( ) be the endpoints of these subintervals and we let
be any sample points in these subintervals, so lies in the i-th
subinterval . Then the definite integral of f from a to b is

∫ ( ) ∑ ( )

provided that this limit exists and gives the same value for all possible
choices of sample points. If it does exist, we say that is integrable on
.
b) If is integrable on , then

∫ ( ) ∑ ( )

where and

Matlab Project - Calculus 1 2019 – 2020 Page 1 of 14


HO CHI MINH CITY UNIVERSITY OF TECHNOLOGY

1.3. The Midpoint Rule


We often choose the sample point to be the right endpoint of the th subinterval because it is
convenient for computing the limit. But if the purpose is to find an approximation to an integral,
it is usually better to choose to be the midpoint of the interval, which we denote by . Any
Riemann sum is an approximation to an integral, but if we use the midpoint we get the following
approximation.

∫ ( ) ∑ ( ̅ ) ( ̅ ( ̅ )

Where

̅ ( )

1.4. The Left Endpoint Rule


For ∫ ( )

 Subdivide into equal subintervals , for , with


, and .
 Approximate subinterval areas with left rectangle areas ∫ ( ) ( )
 Sum subinterval results to approximate ∫ ( ) :

∫ ( ) ( ( ) ( ) ( )

1.5. The Right Endpoint Rule

is here approximated by the value at the Right Endpoint. This gives multiple rectangles with
base and height ( ). Doing this for and adding up the resulting areas
produces.

The Right Endpoint amounts to an underestimation if f is monotonically decreasing, and an


overestimation if it is monotonically increasing. The error of this formula will be

( )
|∫ ( ) |

Matlab Project - Calculus 1 2019 – 2020 Page 2 of 14


HO CHI MINH CITY UNIVERSITY OF TECHNOLOGY

where is the maximum value of ( ) the absolute value of on the interval.

1.6. Definition of First-Order Linear Equation


A first-order linear differetial equation of the form:

( ) ( )

Where and are continuos function of . This first-order linear differential equation is said to
be in standard form.

1.7. Euler’s Method


Approximate values for the solutions of the initial value problem ( ) ( ) ,

with the step size , at , are:

( ) with

Matlab Project - Calculus 1 2019 – 2020 Page 3 of 14


HO CHI MINH CITY UNIVERSITY OF TECHNOLOGY

PROBLEM 1. For each of the functions ƒ below, approximate its derivative at the
given value x = a in two different ways.
First, use a computer microscope (i.e., a graphing program) to view the graph of ƒ near x
= a. Zoom in until the graph looks straight and find its slope.
Second, use a calculator to find the value of the quotient
( ) ( )

for h = .1, .01, .001, ..., .000001. Based on these values of the quotients, give your best
estimate for ƒ’(a), and say how many decimal places of accuracy it has.

a) ƒ(x) = 1/x at x = 2.
b) ƒ(x) = sin(7x) at x = 3.
c) ƒ(x) = x3 at x = 200.
d) ƒ(x) = 2x at x = 5.

SOLUTION
a) ƒ(x) = 1/x at x = 2
Code:
syms x;
fplot(1/x);
xlim ([1.998, 2.0002])
ylim ([0.4995005, 0.5005005])

The slope is:


( ) ( )

Matlab Project - Calculus 1 2019 – 2020 Page 4 of 14


HO CHI MINH CITY UNIVERSITY OF TECHNOLOGY

h ( ) ( )

0.1 -0.2506265664
0.01 -0.2500062502
0.001 -0.2500062502
0.0001 -0.2500000006
0.00001 -0.2500000001
0.000001 -0.2500000000

b) ƒ(x) = sin(7x) at x = 3.

Code:
syms x;
fplot(sin(7*x));
xlim ([2.9998, 3.0002])
ylim ([0.835, 0.84])

The slope is:

Matlab Project - Calculus 1 2019 – 2020 Page 5 of 14


HO CHI MINH CITY UNIVERSITY OF TECHNOLOGY

( ) ( )

h ( ) ( )

0.1140555285
0.1
0.1140583375
0.01
0.1140583656
0.001
0.1140583659
0.0001
0.1140583659
0.00001
0.1140583659
0.000001

c) ( ) = 3 at = 200
Code:
syms x;
fplot(x^3);
xlim ([199.998, 200.002])
ylim ([199.998^3,
200.002^3])

The slope is:

Matlab Project - Calculus 1 2019 – 2020 Page 6 of 14


HO CHI MINH CITY UNIVERSITY OF TECHNOLOGY

( ) ( )

h ( ) ( )

120000.00999999233
0.1
120000.00009988435
0.01
120000.00000186265
0.001
120000.00000186265
0.0001
120000.00006519257
0.00001
119999.9996461
0.000001

d) ( ) = 2 at =5
Code:
syms x;
fplot(2^x);
xlim ([4.9996,5.0004])
ylim ([2^4.9996,2^5.0004])

Matlab Project - Calculus 1 2019 – 2020 Page 7 of 14


HO CHI MINH CITY UNIVERSITY OF TECHNOLOGY

The slope is:

( ) ( )

h ( ) ( )

22.1984753
0.1
22.18808873
0.01
22.1807115
0.001
22.18079795
0.0001
22.18079797
0.00001
22.18079797
0.000001

PROBLEM 2. Write some short programs using Left Endpoint, Right Endpoint and
Midpoint Rules to compute the definite integral of functions ƒ below xi

a) ∫ , divide [1,2] into 10 and 20 subintervals.


b) ∫ , divide [0,2] into 10 and 20 subintervals.

SOLUTION

a) ∫ , divide [1,2] into 10 and 20 subintervals.

Code:
a=1; for i=1:10
b=2; s=s+y(i)*((b-a)./10);
s=0; end
x=linspace(1,2,11); disp ('Left Endpoint 10
y=1./x; subsintevrals:');

Matlab Project - Calculus 1 2019 – 2020 Page 8 of 14


HO CHI MINH CITY UNIVERSITY OF TECHNOLOGY

s end
disp('Right Endpoint 20
a=1; subsintevrals:');
b=2; s
x=linspace(1,2,21);
y=1./x; a=1;
s=0; b=2;
for i=1:20 s=0;
s=s+y(i)*((b-a)./20); z=linspace(1,2,11);
end x=[];
disp('Left Endpoint 20 for i=1:10
subsintevrals:'); x(i)=(z(i)+z(i+1))/2;
s end
y=1./x;
for j=1:10
a=1; s=s+y(j)*((b-a)./10);
b=2; end
s=0; disp('Midpoint 10 subsintevrals:');
x=linspace(1,2,11); s
y=1./x;
for i=2:11 a=1;
s=s+y(i)*((b-a)./10); b=2;
end s=0;
disp('Right Endpoint 10 z=linspace(1,2,21);
subsintevrals:'); x=[];
s for i=1:20
x(i)=(z(i)+z(i+1))/2;
a=1; end
b=2; y=1./x;
s=0; for j=1:20
x=linspace(1,2,21); s=s+y(j)*((b-a)./20);
y=1./x; end
for i=2:20 disp('Midpoint 20 subsintevrals:')
s=s+y(i)*((b-a)./20); s

b) ∫ , divide [0,2] into 10 and 20 subintervals.

Code:
a = 0; %gia tri dau
b = 1; % gia tri cuoi
N = 10; % number of subintervals
deltax = (b-a)/N;
x = a + deltax/2 ; % /2 neu là midpoint , *1 neu la rightpoint , *0 neu la
leftpont
f = exp(-x^2); %pt theo de bai
Ar = 0 ;
for n = 1 : N
f = exp(-x^2); %pt theo de bai
x = x + deltax;
Ar = Ar + f ;
end
disp('midpoint 10 subsintervals: ');
disp(Ar*deltax);

Matlab Project - Calculus 1 2019 – 2020 Page 9 of 14


HO CHI MINH CITY UNIVERSITY OF TECHNOLOGY

a = 0; %gia tri dau


b = 1; % gia tri cuoi
N = 10; % number of subintervals
deltax = (b-a)/N;
x = a + deltax*1 ; % /2 neu là midpoint , *1 neu la rightpoint , *0 neu la
leftpont
f = exp(-x^2); %pt theo de bai
Ar = 0 ;
for n = 1 : N
f = exp(-x^2); %pt theo de bai
x = x + deltax;
Ar = Ar + f ;
end
disp('rightpoint 10 subsintervals: ');
disp(Ar*deltax);

a = 0; %gia tri dau


b = 1; % gia tri cuoi
N = 10; % number of subintervals
deltax = (b-a)/N;
x = a + deltax*0 ; % /2 neu là midpoint , *1 neu la rightpoint , *0 neu la
leftpont
f = exp(-x^2); %pt theo de bai
Ar = 0 ;
for n = 1 : N
f = exp(-x^2); %pt theo de bai
x = x + deltax;
Ar = Ar + f ;
end
disp('leftpoint 10 subsintervals: ');
disp(Ar*deltax);

a = 0; %gia tri dau


b = 1; % gia tri cuoi
N = 20; % number of subintervals
deltax = (b-a)/N;
x = a + deltax/2 ; % /2 neu là midpoint , *1 neu la rightpoint , *0 neu la
leftpont
f = exp(-x^2); %pt theo de bai
Ar = 0 ;
for n = 1 : N
f = exp(-x^2); %pt theo de bai
x = x + deltax;
Ar = Ar + f ;
end
disp('midpoint 20 subsintervals: ');
disp(Ar*deltax);

a = 0; %gia tri dau


b = 1; % gia tri cuoi
N = 20; % number of subintervals
deltax = (b-a)/N;

Matlab Project - Calculus 1 2019 – 2020 Page 10 of 14


HO CHI MINH CITY UNIVERSITY OF TECHNOLOGY

x = a + deltax*1 ; % /2 neu là midpoint , *1 neu la rightpoint , *0 neu la


leftpont
f = exp(-x^2); %pt theo de bai
Ar = 0 ;
for n = 1 : N
f = exp(-x^2); %pt theo de bai
x = x + deltax;
Ar = Ar + f ;
end
disp('rightpoint 20 subsintervals: ');
disp(Ar*deltax);

a = 0; %gia tri dau


b = 1; % gia tri cuoi
N = 20; % number of subintervals
deltax = (b-a)/N;
x = a + deltax*0 ; % /2 neu là midpoint , *1 neu la rightpoint , *0 neu la
leftpont
f = exp(-x^2); %pt theo de bai
Ar = 0 ;
for n = 1 : N
f = exp(-x^2); %pt theo de bai
x = x + deltax;
Ar = Ar + f ;
end
disp('leftpoint 20 subsintervals: ');
disp(Ar*deltax);

PROBLEM 3. Study the Euler method to approximate the solution of first order
differential equations. The following questions concern a rabbit population described by
the logistic model.
( ) rabbits per month
a) What happens to a population of 2000 rabbits after 6 months, after 24
months, and after 5 years? To answer each question, present a table of successive
approximations that allows you to give the exact value to the nearest whole number.
b) Sketch the functions determined by the logistic equation if you start with either
2000 or 4000 rabbits. Compare the two functions. How are they differ? In what
ways are they similar?

SOLUTION
a) What happens to a population of 2000 rabbits after 6 months, after 24
months, and after 5 years? To answer each question, present a table of successive
approximations that allows you to give the exact value to the nearest whole number.

Matlab Project - Calculus 1 2019 – 2020 Page 11 of 14


HO CHI MINH CITY UNIVERSITY OF TECHNOLOGY

6 months 24 months 5 years

Steps Population Rate (R’) Population Rate (R’) Population Rate (R’)
(R) (R) (R)

0.1 3441.877648 296.8016778 12197.19289 624.6332314 24310.50612 67.04778088

0.01 3421.602783 295.3308159 12231.55242 624.7117436 24308.12196 67.27302352

0.001 3419.278986 295.1620234 12234.98876 624.7190762 24307.21124 67.359051

0.0001 3419.371272 295.1687277 12235.39486 624.7199365 24307.11341 67.36829144

Code:

t = input('Initial t: ');

R = input('Initial R: ');

Rprime = 0.1*R*(1-R/25000);

period = input ('Input period of time (months): ');

step = input('Input step: ');

while (t<=period)

t = t + step;

R = R + Rprime*step;

Rprime = 0.1*R*(1-R/25000);

end

b) Sketch the functions determined by the logistic equation if you start with either
2000 or 4000 rabbits. Compare the two functions. How are they differ? In what
ways are they similar?

Matlab Project - Calculus 1 2019 – 2020 Page 12 of 14


HO CHI MINH CITY UNIVERSITY OF TECHNOLOGY

Code:
%3b)
syms R1 R2 Rprimeb toAdd
R1 = 2000;
R2 = 40000;
Value1 = [0,R1];
Value2 = [0,R2];
%This is the plot for 2000 rabbits as starter
for Month = 0:0.01:200
%Step: 0.01, Time: 200 months
Rprimeb = (.1*R1*(1 - (R1/25000)));
R1 = R1+Rprimeb*0.01;
toAdd = [Month,R1];
%Add rows to matrix 2*N
Value1 = [Value1;toAdd];
end
%Plot each point == each row in matrix
subplot(2,2,1)
plot(Value1(:,1),Value1(:,2)), title('From 2000')
%Similarly, for 40000 as starter
for Month = 0:0.01:200
Rprimeb = (.1*R2*(1 - (R2/25000)));
R2 = R2+Rprimeb*0.01;
toAdd = [Month,R2];
Value2 = [Value2;toAdd];
end
subplot(2,2,2)
plot(Value2(:,1),Value2(:,2)), title('From 40000')

Comparing two functions:


Both come close to the horizontal asymptote of 25000
Difference:
For the graph from 2000, the graph increases
For the graph from 40000, the graph decreases

Matlab Project - Calculus 1 2019 – 2020 Page 13 of 14

You might also like