You are on page 1of 2

Finite element modelling - Prof.

Monegato Exercise 2 (Linear systems, piecewise linear interpolation, graphics)

1. Generate a matrix A of order 5 of pseudo-casual numbers, and a vector b such that the exact solution of the linear system Ax = b is the unitary vector x = [1, 1, 1, 1, 1]. Compute the solution of the linear system by using the command x = A\b and compute the relative error with respect to the exact solution by using the euclidean norm. 2. Analyze the linear systems Ax=b with the matrices A=rand(n) and A=hilb(n) for n=5,10 and the vector b chosen such that the solution vector x is the unitary vector. For this purpose, after having solved the aforementioned systems (x=A\b), insert a perturbation in the rst component of the vector b and solve the systems Az=c, where c is the perturbed vector b (as an example, c=b,c(1)=c(1)*(1+10^(-3))). Compare the two solutions x and z and compare the quantities ||xz||2 and ||bc||2 . ||x||2 ||b||2 3. Plot the graph of the function f = sin(x) in the interval I = [0, 2]. Use the MATLAB instruction plot(x,y), with the following input: (a) x=linspace(0,2*pi,8); y=sin(x) (b) x=linspace(0,2*pi,20); y=sin(x) (c) x=linspace(0,2*pi); y=sin(x) 4. Plot the graph of the functions f (x) = xe(x y ) , g(x) = sen(x)sen(y) and h(x) = sen(x)cos(y) over the range 2 x 2, 2 y 2 (help meshgrid, surf). 5. Given the nodes x=linspace(a,b,N), compute the piecewise linear polynomial that interpolates the values y(i) at the nodes x(i), i = 1, , N, where y = f (x). Use the MATLAB instruction s1=interp1(x,y,z) to compute the values of the piecewise polynomial in 100 equally spaced points in [a, b]. Plot in the same gure the piecewise polynomial and the function f for the following cases: (a) f (x) = cos(x), [a, b] = [0, 2], N = 8, (b) f (x) = x3 , [a, b] = [0, 1], N = 3, (c) f (x) =
1 , 1+x2
2 2

[a, b] = [5, 5], N = 10

6. Plot the nodal basis functions associated to the equally spaced partition of the interval [0, 1] into M subintervals Ii = [xi , xi+1 ], with i = 1, , M. The i-th nodal basis function Ni is dened as follows x xi1 , x x x , i1 i xi xi1 Ni (x) = x xi+1 , xi x xi+1 xi xi+1

You might also like