Professional Documents
Culture Documents
Study the content and do the excercises in this document. Read all the comments for the instructions. It will help
you to use Matlab more optimally.
To prevent confusion with notation, only the decimal point will be used when decimal numbers are presented.
Consider the following examples.
1.
The sequence differs from the sequence .
2.
The interval against which represents a four-number.
When calculated values have to be reused, use the full value as saved in Matlab's memory, not a
rounded value.
Table of Contents
1. Calculus concepts................................................................................................................................................2
1.1 Limit................................................................................................................................................................2
Example............................................................................................................................................................2
Example 1........................................................................................................................................................ 3
Exercise 1.........................................................................................................................................................5
1.2 Continuity....................................................................................................................................................... 5
Example 2........................................................................................................................................................ 6
Exercise 2.........................................................................................................................................................6
1.3 Row convergence.......................................................................................................................................... 6
Example 3........................................................................................................................................................ 7
Exercise 3.........................................................................................................................................................7
1.4 Differentiability................................................................................................................................................7
Example 4........................................................................................................................................................ 8
Exercise 4.........................................................................................................................................................8
Exercise 5.........................................................................................................................................................8
1.5 Riemann integral.......................................................................................................................................... 8
Example 5........................................................................................................................................................ 9
Example 6........................................................................................................................................................ 9
Exercise 7.......................................................................................................................................................10
Exercise 8.......................................................................................................................................................10
1.6 Average value.............................................................................................................................................. 10
Exercise 9.......................................................................................................................................................10
2. Calculus theorems............................................................................................................................................. 10
2.1 Mean Value Theorem.................................................................................................................................. 11
1
Example 7...................................................................................................................................................... 11
Example 8...................................................................................................................................................... 13
Exercise 9.......................................................................................................................................................14
2.2 Extreme value theorem............................................................................................................................... 15
Example 10.................................................................................................................................................... 15
Exercise 11.....................................................................................................................................................19
2.3 Intermediate value theorem......................................................................................................................... 19
Exercise 12.....................................................................................................................................................20
2.4 Mean value theorem for integrals................................................................................................................20
Exercise 13.....................................................................................................................................................20
2.5 Taylor theorem.............................................................................................................................................20
Exercise 14.....................................................................................................................................................21
Exercise 15.....................................................................................................................................................21
Exercise 16.....................................................................................................................................................22
3. Can you do the following in Matlab?.................................................................................................................22
Functions................................................................................................................................................................ 22
Riemann sum with right end points................................................................................................................... 23
Answers.................................................................................................................................................................. 23
1. Calculus concepts
The following Calculus concpets are important for the numerical handling of Mathematical problems.
1.1 Limit
Definition 1: A function f defined on a set X of real numbers has a limit L at if, given any real number ,
there exists a real number such that , whenever and (it is
indicated by Fig. 1.1, Faires/Burden).
Example
2
Use the definition to show that , where
Answer: Let . We must just show that there exist a constant δ (that may depend on ϵ) such that
whenever . We have:
Take .
Example 1
Determine the limit of the function at the point by executing the instructions below.
% Limiete in Matlab word met die ingeboude Matlabfunksie limit in Symbolic Toolbox bereken.
% Limits in Maltab are calculated with the built-in Matlab function limit in Symbolic Toolbox.
clear
syms x
f(x)=cos(x^2)
f(x) =
L=limit(f(x),x,pi/4)
L =
Le = 0.8157
% Om meer desimale waardes van die antwoord te sien, gebruik format long. Die verstekstelling i
% To see more decimals of the answer, use format long. The default setting is fornat short.
format long
Lel=eval(L)
Lel =
0.815704517422009
Look at the "workspace". The saved expressions and value are shown there.
eval(limit(6*log(exp(1)+x)*sin(pi*x)/(pi^2*x),x,0))
ans =
1.909859317102744
3
% Funksie simbolies gedefinieer.
% Function defined symbolically.
clear
syms x
f(x)=sin(x^2)+2/x+x*exp(x)
f(x) =
f(pi/3)
ans =
eval(f(pi/3))
ans = 5.7837
g(pi/3)
ans = 5.7837
Let ook op na die verskil in afvoer vir die volgende instruksies. / Also note the difference in output for the
following instructions.
limit(k(x),x,0,'left')
ans =
limit(k(x),x,0,'right')
ans =
eval(limit(k(x),x,0,'left'))
ans = -Inf
eval(limit(k(x),x,0,'right'))
4
ans = Inf
k(0)
ans = Inf
h(x) =
limit(h(x),x,0,'left')
ans =
limit(h(x),x,0,'right')
ans =
h(0)
Exercise 1
Copy and paste the instructions and determine the limit of the function at the point and 0.
1.2 Continuity
5
Definition 2: Let f be a function defined on a set X of real numbers and . Then f is continuous at if
both and exist, and
Example 2
Determine whether the function is continuous in the point by executing the instructions below.
% Bepaal kontinuïteit.
% Determine continuity.
clear
syms x
f(x)=sin(x^2)
%evaluate the lim f(x) as x approaches pi/3
eval(limit(f(x),x,pi/3))
%evaluate f(pi/3)
eval(f(pi/3))
%compare
eval(limit(f(x),x,pi/3))-eval(f(pi/3))
Exercise 2
Copy and paste the instructions and determine whether the function is continuous in the point 100.
Copy and paste the instructions and determine whether the function is continuous in the point 0.
The output for the limit is "NaN" which means "Not a Number". The limit therefore does not exists. From the
error message in the output, the function does not exist in the point 0 since it causes division by zero which is
not defined. The function is therefore discontinous in the point 0.
6
is indicated by .
Definition 3: An infinite row converges to the number x if for any real value , there exists a positive
Example 3
Consider the row
ans =
limit(1+1/n,n,0)
ans =
Exercise 3
Copy and paste the intstructions and determine the limit of
1.4 Differentiability
A function f defined on the real set X with is differentiable in the point if
7
(Fig 1.2, Faires/Burden)
Remark: If a function f defined on the real set X with is differentiable in the point , then it is continuous
in the point .
Example 4
Use the definition to show that is differentiable in the point , and find .
Answer:
Exercise 4
Exercise 5
8
The Riemann integral of the function f over the interval is the following limit, provided it exists (Fig. 1.6,
Faires/Burden)
with and .
Example 5
A Matlab fuction which calculate Riemann sums is given at the end of this document. To calucluate the
Riemann sum for as defined above, over the interval for 10 subintervals, the Matlab function can
be called by executing the instruction below. Study the code in the Matlab function and execute the instruction.
R1=riemannsum(h,0.4,1.4,10)
R1 =
15.083127439231083
Example 6
9
The exact integral value can be determined by using the built-in Matlab function integral. To calucluate the
integral for as defined above, over the interval , the Matlab functions can be called by executing
the instruction below. Determine the integral and compare the answer with the Riemann sum.
Exercise 7
Calucluate the Riemann sum for as defined above, over the interval for 100 subintervals and
compare the value with the integral value.
Exercise 8
Calucluate the Riemann sum for over the interval for 15 and 200 subintervals and compare
the value with the integral value.
Exercise 9
Calucluate the average value for over the interval .
2. Calculus theorems
The following Calculus theorems are important for the numerical handling of Mathematical problems.
Consider a real set X. The set of all functions having order continuous derivatives on X is indicated by
.
10
means the set of all functions with continuous first order derivatives (and therefore the function as well)
on .
Example 7
Consider the function . Sketch the function on the interval and the secant through the
eindpoints on the same set of axes. Read the comments and execute the instructions.
f(x) =
df(x)=diff(f(x))
df(x) =
g(x)=(f(pi/2)-f(0))/(pi/2-0)*(x-0)+f(0)
g(x) =
fplot(f(x),[0 pi/2])
11
hold on
fplot(g(x),[0 pi/2])
hold off
% Teken funksies met numeries. Gebruik verkieslik hierdie metode aangesien Matlab die instruksi
% Sketch functions with numerically. Preferably use this method since Matlab execute the instru
clear
f=@(x)sin(x.^2)
g=@(x)(f(pi/2)-f(0))/(pi/2-0).*(x-0)+f(0)
fplot(f,[0 pi/2])
hold on
fplot(g,[0 pi/2])
hold off
12
Example 8
To determine the point c for the function over the interval , the following instructions can be
used. Read the comments and execute the instructions. Note the three different methods and their output.
% solve is 'n ingeboude Matlabfunksie in Symbolic Toolbox en los die vergelyking simbolies op.
% solve is a built-in Matlab function int Symbolic Toolbox and solve the equation symbolically.
% Nie alle vergelykings kan simbolies opgelos word nie.
% Not all equations can be solved symbolically.
% vpasolve is 'n ingeboude Matlabfunksie wat 'n vergelyking numeries oplos vir 'n simboliese ve
% vpasolve is a built-in Matlab function that solves an equation numerically for a symbolic var
% Metode / Method 1
clear
syms x c
f(x)=sin(x^2)
f(x) =
df(x)=2*x*cos(x^2)
df(x) =
solve(df(c)==(f(pi/2)-f(0))/(pi/2-0))
13
Warning: Unable to solve symbolically. Returning a numeric solution using vpasolve.
ans =
% Metode / Method 2
clear
syms x c
f(x)=sin(x^2)
f(x) =
df(x)=2*x*cos(x^2)
df(x) =
vpasolve(df(c)==(f(pi/2)-f(0))/(pi/2-0))
ans =
% Metode / Method 3
clear
syms c
f=@(x)sin(x.^2)
df=@(x)2*x.*cos(x.^2)
vpasolve(df(c)==(f(pi/2)-f(0))/(pi/2-0))
ans =
The third method is the prefered method since Matlab execute instructions faster when functions are defined
numerically.
Exercise 9
Consider the function . Sketch the function on the interval and the secant through the eindpoints
on the same set of axes. Also determine the point c for the function over the interval . Compare
14
2.2 Extreme value theorem
Theorem: If , then there exist numbers such that
, for all
Example 10
Consider the function and differentiable on defined by
Local minimum and maximum values will occur at and global minimum and maximum values at
or at the endpoints of the interval. Matlab can be used to determine these values on the interval
as follows. Execute the instructions.
% Bepaal ekstreemwaardes.
% Determine extreme values.
clear
% Funksie / Function
f=@(x)9*cos(x)-x.^2+sqrt(x)
fplot(f,[0 7])
grid on
15
% Eerste afgeleide / First derivative
df=@(x)-9*sin(x)-2*x+0.5./sqrt(x)
fplot(df,[0 7])
grid on
16
fplot(df,[4 5])
grid on
17
Zeros for is expected more or less at 0.1, 4.4 and 4.6. Execute the instructions.
syms c
C=vpasolve(df(c)==0)
C =
Double click on the variable C in the Workspace to see the full value.
This solution is a complex number not corresponding to the graph of . Although vpasolve is more versatile
than solve, it does not always give accurate results. Matlab also uses other numerical methods to solve
equations or determine zeros.
% fzero is 'n numeriese metode wat een nulpunt bepaal indien 'n geskatte waarde naby die nulpun
% fzero is a numerical method which determines one zero if an estimate value is given.
c1=fzero(df,0.1)
c1 = 5.5220e-30
c2=fzero(df,4.4)
c2 = 4.1434e-23
c3=fzero(df,4.6)
c3 = 1.0538e-22
f0=f(0)
f0 = 3
fc1=f(c1)
fc1 = 3
fc2=f(c2)
fc2 = 3
fc3=f(c3)
fc3 = 3
18
f7=f(7)
f7 = 8.7733e+03
dfc1=df(c1)
dfc1 = 1.6566e-29
dfc2=df(c2)
dfc2 = 1.2430e-22
dfc3=df(c3)
dfc3 = 3.1615e-22
ddfc1=ddf(c1)
ddfc1 = -1.9266e+43
ddfc2=ddf(c2)
ddfc2 = -9.3735e+32
ddfc3=ddf(c3)
ddfc3 = -2.3109e+32
Exercise 11
Follow the same steps as above and use the Matlab function fzero to determine the extreme values for
.
19
Exercise 12
Determine whether the function has a zero on the interval without skethcing the function.
Exercise 13
Consider the function on the interval . Determine the point according to the
expression above. Sketch the function over the interval en on the same set of axes.
20
Theorem: Suppose , exists on , and . For each there exists a
number between and x such that
where
Remark: The number is dependent on the x where is determined, but not easy to determine. In
practice an absolute maximum is determined on an interval.
Exercise 14
Determine , , , and for the function about the point and sketch
them together with on the same set of axes for . Sketch them one by one together with the function to
see the build up.
Exercise 15
Use some of your results of Exercise 14 for the function about the point to determine the
following values.
1.
for
2.
for
3.
for
21
% P3(X)
% abs(f(X)-P3(X))
% Dubbelkliek op die veranderlikes in Workspace om al die waardes te sien.
% Double click on the varialbes in Workspace to see all the values.
% Kliek op die afvoer om al die waardes te sien.
% Click on the output to see all the values.
Exercise 16
Determine for the function about the point and use it to determine the following.
1. The maximum absolute error for and compare your answer with above. (Determine
.) HINT: Sketch over the interval to get an estimate maximum value for
2. The maximum absolute error for on the interval and compare your answer with
Functions
22
Copy and save the code of the function in a new "script" as name.m where "name" is the name of the function.
You can then call and execute it directly from the "Command Window" if it is saved in the "Current Folder", the
folder as indicated just below the toolbar. You can change the "Current Folder" by clicking on it. The function
can also be copied in a "script" or "live script" together with other instructions, including the instruction calling
the function. It just has to be at the end of the document as done here.
Answers
1. 6; NaN
2. Continuous; Discontinous does not exist
3. e
4.
5. Non-differentiable
6. 25.7963
7. 13.9867
8. 0.7062; 0.7692; 0.7727
9. 0.2459
10. 3.4641
11. g(1.9173) = 3,7561 local maximum value; g(4.9338) = -8.9935 local and global minimum value;
g(8.02861) = 16.7459 local and global minimum value
12. f(1) = 0.8415 > 0, f(2) = -0.7568 < 0, f continuous, thus there exists a c so that f(c) = 0 on [1,2].
13. 0.7452
14. Note how the polynomials follows larger parts of the function as the terms increase.
15. (1) 0.000; 0.8415; 0.9915; 0.7781; 0.6243; 0.2489; -0.7568; -0.4303; -0.1324. (2) -13.0700; 0.3809;
0.8975; 0.7779; 0.6243; 0.2472; -0.9764; -4.7139; 30.5064. (3) 13.0700; 0.4606; 0.0940; 0.0001; 0;
0.0018; 0.2196; 4.2836; 30.6387
23
16. (1) For : compare with . (2) For
: for . Compare with for .
24