Anm 2022 0629 c2 Com Exam ENG
Anm 2022 0629 c2 Com Exam ENG
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)
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)
25
20
15
10
-5
-1 -0.5 0 0.5 1 1.5 2 2.5 3