[Solved] FYS4150 Project1-vector and matrix operations

$25

File Name: FYS4150_Project1-vector_and_matrix_operations.zip
File Size: 423.9 KB

SKU: [Solved] FYS4150 Project1-vector and matrix operations Category: Tag:
5/5 - (1 vote)

The aim of this project is to get familiar with various vector and matrix operations, from dynamic memory allocation to the usage of programs in the library package of the course. For Fortran users memory handling and most matrix and vector operations are included in the ANSI standard of Fortran 90/95. Array handling in Python is also rather trivial. For C++ user however, there are several possible options. Two are listed here.

  • For this exercise we recommend that you make your own functions for dynamic memory allocation of a vector and a matrix. You dont need to write a class for this operations. Use then the library package lib.cpp with its header file lib.hpp for obtaining LU-decomposed matrices, solve linear equations etc.
  • A very good and often recommended library for C++ handling of arrays is the library Armadillo, to be found at url{arma.sourceforge.net}. We will discuss the usage of this library during the lab sessions and lectures. Armadillo has also an interface to Lapack functions for solving systems of linear equations. Alternatively you can use the Eigen library, which has much of the same functionality as Armadillo.

Your program, whether it is written in C++, Python, Fortran or other languages, should include dynamic memory handling of matrices and vectors.

The material needed for this project is covered by chapter 6 of the lecture notes, in particular section 6.4 and subsequent sections.

Many important differential equations in Science can be written as linear second-order differential equations

f“>ff is normally called the inhomogeneous term and Φ“> is generated by a localized charge distribution ∇2Φ=−4πρ(r).“>2=4(r).2=4(r).

With a spherically symmetric ρ(r)“>(r)(r) the equations simplifies to a one-dimensional equation in 1r2ddr(r2dΦdr)=−4πρ(r),“>1r2ddr(r2ddr)=4(r),1r2ddr(r2ddr)=4(r),

which can be rewritten via a substitution d2ϕdr2=−4πrρ(r).“>d2dr2=4r(r).d2dr2=4r(r).

The inhomogeneous term ρ“> multiplied by −4π“>44.

We will rewrite this equation by letting r→x“>rxrx. The general one-dimensional Poisson equation reads then

−u″(x)=f(x),x∈(0,1),u(0)=u(1)=0.“>u(x)=f(x),x(0,1),u(0)=u(1)=0.u(x)=f(x),x(0,1),u(0)=u(1)=0.

and we define the discretized approximation to vi“>vivi with grid points x0=0“>x0=0x0=0 to h=1/(n+1)“>h=1/(n+1)h=1/(n+1). We have then the boundary conditions u“>uu with

fi=f(xi)“>fi=f(xi)fi=f(xi). Show that you can rewrite this equation as a linear set of equations of the form

A“>AA is an A=[2−10……0−12−10……0−12−10………………0…−12−10…0−12],“>A=210001210120110021012,A=[210012100121001210012],

and f(x)=100e−10x“>f(x)=100e10xf(x)=100e10x, and keep the same interval and boundary conditions. Then the above differential equation has a closed-form solution given by A“>AA in terms of one-dimensional vectors 1:n“>1:n1:n. Our linear equation reads

vi“>vivi. A tridiagonal matrix is a special form of banded matrix where all the elements are zero except for those on and immediately above and below the leading diagonal. Develop a general algorithm first which does not assume that we have a matrix with the same elements along the diagonal and the non-diagonal elements. The algorithm for solving this set of equations is rather simple and requires two steps only, a decomposition and forward substitution and finally a backward substitution.

Before we proceed with the solution of the differential equation, you should now plan the organization of your data flow. Here you will find it convenient to define vectors that will contain the matrix elements, the solution to the problem and the function be found here

Your first task is to set up the general algorithm (assuming different values for the matrix elements) for solving this set of linear equations. Find also the precise number of floating point operations needed to solve the above equations. For the general algorithm you need to specify the values of the array elements b“>bb and 10×10“>10101010, 1000×1000“>1000100010001000. That means that you select n=100“>n=100n=100 and x∈(0,1)“>x(0,1)x(0,1). The different number of grid points corresponds to different step lengths n=106“>n=106n=106 grid points.

Project 1 d):

Compute the relative error in the data set ϵi=log10(|vi−uiui|),“>i=log10(viuiui),i=log10(|viuiui|),

as function of ui“>uiui and n“>nn to 10×10“>10101010, 1000×1000“>1000100010001000. Here you should use the library functions provided on the webpage of the course. Alternatively, if you use armadillo as a library, you can use the similar function for LU decomposition. The armadillo function for the LU decomposition is called solve“>solvesolve. Use for example the unix function time when you run your codes and compare the time usage between LU decomposition and your tridiagonal solver. Alternatively, you can use the functions in C++, Fortran or Python that measure the time used.

Make a table of the results and comment the differences in execution time How many floating point operations does the LU decomposition use to solve the set of linear equations? Can you run the standard LU decomposition for a matrix of the size https://www.uio.no/english/services/it/education/canvas/ with your normal UiO username and password.

  • Upload only the report file! For the source code file(s) you have developed please provide us with your link to your github domain. The report file should include all of your discussions and a list of the codes you have developed. Do not include library files which are available at the course homepage, unless you have made specific changes to them. Alternatively, you can just upload the address to your GitHub or GitLab repository.
  • In your git repository, please include a folder which contains selected results. These can be in the form of output from your code for a selected set of runs and input parameters.
  • In this and all later projects, you should include tests (for example unit tests) of your code(s).
  • Comments from us on your projects, approval or not, corrections to be made etc can be found under your Canvas domain and are only visible to you and the teachers of the course.
  • Reviews

    There are no reviews yet.

    Only logged in customers who have purchased this product may leave a review.

    Shopping Cart
    [Solved] FYS4150 Project1-vector and matrix operations
    $25