Docsity

Esercizi di Algebra Lineare e Geometria con MATLAB - Prof. Carlini, Esercizi di Algebra Lineare e Geometria Analitica

Toggle sidebar
bg1
Linear Algebra and Geometry - Scientific Computing
Exercise session 0
Topics: matrices and vectors manipulation, plots of functions and Matlab
programming language
1. Define the vector x=[1:-0.1:0]. Type the following MATLAB instructions, understanding their meaning:
a) x([1 4 3]);
b) x([1:2:7 10])=zeros(1,5);
c) x([1 2 5])=[0.5*ones(1,2) -0.3];
d) y=x(end:-1:1).
2. Define the matrix:
A=
1 2 3 4
5 6 7 8
9 10 11 12
and type the following MATLAB instructions, understanding their meaning:
a) size(A);
b) A(1:2,4), A(:,3), A(1:2,:), A(:,[2,4]), A([2 3 3],:);
c) A(3,2)=A(1,1);
d) A(1:2,4)=zeros(2,1);
e) A(2,:)=A(2,:)-A(2,1)/A(1,1)*A(1,:).;
3. Define the matrix:
A=
123456
5678910
9 10 11 12 13 14
15 16 17 18 19 20
After that:
a) assemble the matrix Bmade by the columns of Ain reverse order (that is to say the first column
of Bis the 6th of A, the 2nd of Bis the 5th of A, ...).
b) assemble the matrix made by the even columns of A;
c) assemble the matrix made by the odd rows of A;
d) assemble the matrix made by rows 1,4,3 and columns 5,2 of A;
e) assemble the vector made by the diagonal elements akk, k = 1, ..., 4 of A;
4. Use the MATLAB command diag to define a 10 ×10-tridiagonal matrix Bin which the main diagonal
elements are all equal to 5 while the sub-diagonal elements are equal to -1 and the super-diagonal
elements are equal to 3. Set the elements of the intersection between column 6 and 9 and rows 5 and
8 equal to 2.
5. Use the Matlab command plot to graphically represent the following mathematical functions:
f(x) = sin(x)x∈[−π, π] ;
f(x) = exx∈[−1,1] ;
f(x) = e−x2x∈[−π, π] ;
1
pf2
Discount

In offerta

Anteprima parziale del testo

Scarica Esercizi di Algebra Lineare e Geometria con MATLAB - Prof. Carlini e più Esercizi in PDF di Algebra Lineare e Geometria Analitica solo su Docsity!

Linear Algebra and Geometry - Scientific Computing

Exercise session 0

Topics: matrices and vectors manipulation, plots of functions and Matlab

programming language

  1. Define the vector x=[1:-0.1:0]. Type the following MATLAB instructions, understanding their meaning:

a) x([1 4 3]); b) x([1:2:7 10])=zeros(1,5); c) x([1 2 5])=[0.5*ones(1,2) -0.3]; d) y=x(end:-1:1).

  1. Define the matrix:

A =

and type the following MATLAB instructions, understanding their meaning:

a) size(A); b) A(1:2,4), A(:,3), A(1:2,:), A(:,[2,4]), A([2 3 3],:); c) A(3,2)=A(1,1); d) A(1:2,4)=zeros(2,1); e) A(2,:)=A(2,:)-A(2,1)/A(1,1)*A(1,:).;

  1. Define the matrix:

A =

After that:

a) assemble the matrix B made by the columns of A in reverse order (that is to say the first column of B is the 6th^ of A, the 2nd^ of B is the 5th^ of A, ...). b) assemble the matrix made by the even columns of A; c) assemble the matrix made by the odd rows of A; d) assemble the matrix made by rows 1,4,3 and columns 5,2 of A; e) assemble the vector made by the diagonal elements akk, k = 1, ..., 4 of A;

  1. Use the MATLAB command diag to define a 10 × 10-tridiagonal matrix B in which the main diagonal elements are all equal to 5 while the sub-diagonal elements are equal to -1 and the super-diagonal elements are equal to 3. Set the elements of the intersection between column 6 and 9 and rows 5 and 8 equal to 2.
  2. Use the Matlab command plot to graphically represent the following mathematical functions:

f (x) = sin(x) x ∈ [−π, π] ; f (x) = ex^ x ∈ [− 1 , 1] ; f (x) = e−x 2 x ∈ [−π, π] ;

f (x) = sin( x x) x ∈ (0, 4 π] ; f (x) = x sin( (^1) x ) x ∈ (0, 2] ;

  1. Graphically represent the mathematical function:

f (x) =

100(1 − 0. 01 x^2 )^2 + 0. 02 x^2 (1 − x^2 )^2 + 0. 1 x^2

x ∈ [0. 1 , 100] ,

using the MATLAB commands plot and loglog. Evaluate the function at sufficiently large number of points in the range of interest. Comment the results.

  1. Write a MATLAB function which evaluates the mathematical function:

f (x) =

− 2 x, x < 0 , 0 , x = 0, 2 x, x > 0 ,

both at a generic point x and at each point of a vector. After that, graphically represent the function f in the interval [-1,1].

  1. Write a MATLAB f unction in order to approximate the value of the function f (x) = ex^ in a neighborhood of x = 0 by means of Taylor polynomial

ex^ ≈ 1 + x +

x^2 2!

x^3 3!

xn n!

of degree n, 0-centered. Stop the summation when the term x

i i! is less than a fixed tolerance^ tol. Run the function with x = 1, tol = 1. 0 e − 10 and compute the relative error linked to the value of the polynomial at x, using as exact value the one given by the Matlab function exp(x).