inm_hw1
TRANSCRIPT
-
8/2/2019 inm_hw1
1/2
Universitat Duisburg-Essen Winter Term 2011/12Fakultat fur Mathematik 12. Oktober 2011Computational MechanicsDipl.-Math. Andreas FischleDipl.-Math. Alexander Heinlein
Introduction to Numerical Methods
Homework 1
This first set of homeworks is intended to introduce you to the Matlab program-ming language in a playful way.
It may be helpful to use the diary function to document the output of Matlab.
Exercise 1: (5 Points / Programming)
(i) Use Matlab to print the machine representations of the real numbers 43
,0.0000012345 and 1.2345e06 in the following formats
(1) short ; short e ; short g
(2) long ; long e ; long g
(3) rat
and explain the results. What is the meaning of e in this context?
(ii) What happens if you use the following commands in Matlab
(1) f1 = 3 3 ;
(2) f2 = 3 3 ; g1 = [3 , 1; 1 , 3]3
(3) f3 = 3. 2 g2 = [3 , 1; 1 , 3] . 3
(4) 3 + 3
(5) disp(Hello world!); disp(Introduction to Numerical Methods); What is the difference between g1 and g2, cf., (2) and (3)?
-
8/2/2019 inm_hw1
2/2
Exercise 2: (5 Points / Programming)Let A = (aij)i,j=1...n be the matrix with entries aij = i/j and x the vector xj = jfor j = 1 . . . n, i.e.,
A =
1 12
1
3
1
n
2 12
3
.. .
2
n
3 32
. . . . . . 3n
.... . . . . . . . .
...n n
2 1
, x =
1
23...n
.
(i) Try three different ways to build the matrix A, i.e.,
(1) using 2 nested for-loops(for k=1... for l=1... A(k,l)=k/l; end end)
(2) using one vector and one for-loop
(k=1:n; for l=1... A(:,l) = k/l; end)
(3) using the product of two vectors(k=(1:n); l=ones(1,n)./k; A = k * l;)
(ii) Build the matrix A and the vector x in Matlab and compute the matrix-vector product y = Ax for n = 3, 5, 10, 100, 1000.Verify the solution by your theoretical knowledge on matrix-vector multi-plication.
Exercise 3: (6 Points / Programming)
(i) Write a MATLAB function function x = make inter(n) which takes anumber of nodes n and returns a vector x containing n equidistant nodeswith a constant spacing h = 1
n1in the interval [0, 2] R.
(ii) Plot the functions sin(x) and cos(x) separately on this interval with h =0.01. How many nodes do you need?
(iii) Plot the sin(x) function for every step size h = 1, 0.5, 0.1, 0.01 and supe-rimpose all of these plots to obtain a single combined plot.
Due date: Thursday, 20 October 2011
Please, follow the guidelines described in the Syllabus on the homepage whichdescribes how to turn in your homework. Thank you for your cooperation.