0% found this document useful (0 votes)
32 views2 pages

Anm 2022 0629 c2 Com Exam ENG

The document describes a computer exam for an advanced numerical methods course consisting of 3 exercises: 1. Writing functions for piecewise polynomial interpolation and plotting the results. 2. Writing functions for calculating zeros of Chebyshev polynomials, Gaussian quadrature integration, and applying it to a specific integral. 3. Solving a pendulum differential equation initial value problem using MATLAB's ode45 solver and plotting the solution.

Uploaded by

kike
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views2 pages

Anm 2022 0629 c2 Com Exam ENG

The document describes a computer exam for an advanced numerical methods course consisting of 3 exercises: 1. Writing functions for piecewise polynomial interpolation and plotting the results. 2. Writing functions for calculating zeros of Chebyshev polynomials, Gaussian quadrature integration, and applying it to a specific integral. 3. Solving a pendulum differential equation initial value problem using MATLAB's ode45 solver and plotting the solution.

Uploaded by

kike
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

NAME: ................................................................................................... Time: 75 min.

ADVANCED NUMERICAL METHODS – COMPUTER EXAM


JUNE 29, 2022 – EXTRAORDINARY CALL

EXERCISE 1 (4.5 points)


a) Write a function that returns the vectorized function handle p of the piecewise
polynomial p(x) such that
p( x) [ x , x = pi ( x) = ai + bi ( x − xi ) + ci ( x − xi )2 + di ( x − xi )3 (i = 0,1, 2,..., n − 1)
i i +1 )

Use as input arguments the vectors ai, bi, ci, di, xi containing the
coefficients of the polynomial pieces and the values of xi, respectively.
Evaluate the polynomial pieces using the Horner variant without loops that run over the
points x where p(x) is evaluated. (2.5p)
b) Write a script that represents p(x) as a red line of width 2 points when the
coefficients ai are respectively 2, 1, 1, 2, the coefficients bi are −1, 0, −2, 11, the
coefficients ci are −1, 2, −4, 17, the coefficients di are 1, −2, 7, 1, and the points xi are
−1, 0, 1, 2, 3. In the same figure, make the script also plot the interpolation points
(xi, p(xi)) using as markers black dots of size 20. Add a label identifying what the
interpolation data and p(x) are, and a title showing the number of polynomial pieces by
concatenating strings. (2p)

EXERCISE 2 (4.25 points)


a) Write a function that calculates the zeros of the Chebyshev polynomial of the first
kind of degree m over an arbitrary interval [a, b] without any for loop. Make the input
arguments be the degree of the polynomial and a 2-element vector with the interval
[a, b]. The zeros in [−1, 1] are:
 (2k + 1)π 
tk = cos   (k = 0,1, 2..., m − 1) (1p)
 2m 
1 f (t )
b) Write a function that approximates the integral  dt by using a Gauss-
−1
1− t2
Chebyshev quadrature iterative process that stops with a “relative-error” criterion.
Use as input arguments the vectorized function handle to the subintegral function f (t)
and the per-unit value ε of the stopping criterion. Make the output arguments the
approximate value of the integral and the number of iterations made. Let this function
call the one of section a). (2.25p)
n
1 f (t ) π
Formulas: −1 1 − t 2 dt ≈ 
i =0
wi f (ti ) where wi =
n +1
∀i .

c) Write a script using the function of section b) to calculate the integral


2
1 (1 − x ) 2 − x
−1 1 − x 2 dx with stopping criterionε = 10 . Also obtain the value of that
−15

integral using Matlab/Octave native functions with the same precision. Show the results
with 16 significant digits. (1p)
Solution: Q = 2.203345731824744 after 13 iterations.
EXERCISE 3 (1.25 points)
The motion of a pendulum of mass m, radius r and friction coefficient k under gravity g
is governed by the ODE α ′′(t ) = − g r sin α (t ) − k m α ′(t ) where α(t) is its angle with
the downward vertical. For g = 9.8, r = 3, m = 5, k = 0.1 (all units SI) and the initial
conditions α(0) = 0, α'(0) = 3.6549, write a script that solves the initial-value
problem for t ∈ [0, 10] using the Matlab/Octave native ode45 function. Let the script
also plot the angle α(t) over that interval. (1.25p)

Approximate solution figures for exercises 1 and 3:


Piecewise polynomial with 4 pieces
35
Piecewise polynomial p(x)
30 Points (x , p(x ))
i i

25

20

15

10

-5
-1 -0.5 0 0.5 1 1.5 2 2.5 3

You might also like