0% found this document useful (0 votes)
102 views2 pages

Inm hw1

This document provides instructions for the first homework assignment in an introduction to numerical methods course. It includes 3 exercises to familiarize students with Matlab programming, such as printing machine representations of numbers, performing basic arithmetic and matrix operations, and plotting functions for different step sizes of intervals. Students are asked to complete the exercises, which involve basic programming and numerical computations in Matlab, and submit their work by the given deadline.

Uploaded by

mahesh84psg
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
102 views2 pages

Inm hw1

This document provides instructions for the first homework assignment in an introduction to numerical methods course. It includes 3 exercises to familiarize students with Matlab programming, such as printing machine representations of numbers, performing basic arithmetic and matrix operations, and plotting functions for different step sizes of intervals. Students are asked to complete the exercises, which involve basic programming and numerical computations in Matlab, and submit their work by the given deadline.

Uploaded by

mahesh84psg
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Universitt Duisburg-Essen a Fakultt fr Mathematik a u Computational Mechanics Dipl.-Math. Andreas Fischle Dipl.-Math.

Alexander Heinlein

Winter Term 2011/12 12. Oktober 2011

Introduction to Numerical Methods Homework 1


This rst set of homeworks is intended to introduce you to the Matlab programming 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)


4 (i) Use Matlab to print the machine representations of the real numbers 3 , 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) f 1 = 3 3 ; (2) f 2 = 33 ; (3) f 3 = 3.2 (4) 3 + 3 (5) disp(Hello world!); disp(Introduction to Numerical Methods); What is the dierence between g1 and g2, cf., (2) and (3)? g1 = [3 , 1; 1 , 3]3 g2 = [3 , 1; 1 , 3] .3

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 = j for j = 1 . . . n, i.e., 1 1 n 1 1 2 3 1 .. 2 2 2 . n 2 1 3 3 3 ... ... 3 , x = 3 . A= n . . .2 . ... . . . . . .. .. . . n n n 1 2 (i) Try three dierent 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 matrixvector product y = Ax for n = 3, 5, 10, 100, 1000. Verify the solution by your theoretical knowledge on matrix-vector multiplication. Exercise 3: (6 Points / Programming) (i) Write a MATLAB function function x = make inter(n) which takes a number of nodes n and returns a vector x containing n equidistant nodes 1 with a constant spacing h = n1 in 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 superimpose 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 which describes how to turn in your homework. Thank you for your cooperation.

You might also like