17NTL37 Simulation and Modelling Lab syllabus for NT



A d v e r t i s e m e n t

Module-1 Laboratory Experiments 0 hours

Evaluate using MATLAB:

Solve using MATLAB the following array operations:

(a) 1+ [2 3 –1]. (b) 3 x [1 4 8] . (c) [1 2 3] x [0 –1 1]. (d) Square each element of the vector [2 3 1].

Consider the given function

Write a Matlab code to plot with the elements of its vector representation

Consider the following linear system:

2x1 + 2 x2=18

-x1 + 2 x2=2

solve the system using the graphical method with MATLAB

(a) Find the determinant and inverse of A (using Matlab). (b) Let B be the matrix obtained from A by rounding off to three decimal places (1.2969 7→ 1.297). Find the determinant and inverse of B. How do A−1 and B−1 differ? Explain how this happened. (c) Set b1 = [1.2969; 0.2161] and do x = A \\ b1 . Repeat the process but with a vector b2 obtained from b1 by rounding off to three decimal places. Explain exactly what happened. Why was the first answer so simple? Why do the two answers differ by so much?

 

Write a well-commented function program for the function x2 e−x2 , using entry-wise operations (such as .* and .^). To get ex use exp(x). Include adequate comments in the program. Plot the function on [−5, 5]. Turn in printouts of the program and the graph.

Write a well-commented script program that graphs the functions sin x, sin 2x, sin 3x, sin 4x, sin 5x and sin 6x on the interval [0, 2π] on one plot. (π is pi in Matlab.) Include comments in the program. Turn in the program and the graph.

Suppose a ball is dropped from a height of 2 meters onto a hard surface and the coefficient of restitution of the collision is .9 (see Wikipedia for an explanation). Write a well-commented script program to calculate the total distance the ball has traveled when it hits the surface for the n-th time. Enter: format long. By trial and error approximate how large n must be so that total distance stops changing. Turn in the program and a brief summary of the results.

(a) Write a well-commented Matlab function program myinvcheck that

  • a. makes a n × n random matrix (normally distributed, A = randn(n,n)),
  • b. calculates its inverse (B = inv(A)),
  • c. multiplies the two back together.
  • d.calculates the residual (difference from the desired n × n identity matrix eye(n)), and.
  • e. returns the norm of the residual.

(b) Write a well-commented Matlab script program that calls myinvcheck for n = 10, 20, 40, . . . , 2 i10 for some moderate i, records the results of each trial, and plots the error versus n using a log plot. (See help loglog.) What happens to error as n gets big? Turn in a printout of the programs, the plot, and a very brief report on the results of your experiments.

You are given the following data:

> t = [ 0 .1 .499 .5 .6 1.0 1.4 1.5 1.899 1.9 2.0] > y = [ 0 .06 .17 .19 .21 .26 .29 .29 .30 .31 .31]

(a) Plot the data, using ”*” at the data points, then try a polynomial fit of the correct degree to interpolate this number of data points: What do you observe. Give an explanation of this error, in particular why is the term badly conditioned used?

(b) Plot the data along with a spline interpolant. How does this compare with the plot above? What is a way to make the plot better?

Last Updated: Tuesday, January 24, 2023