Starting from:
$35

$29

Matlab Sheet (Basics) Solution


Prob 1) The surface area of a right circular cylinder is given by the equation

    • = 2 r(r + h);

where h is the height and r is the radius of the cylinder. Write a Matlab code to nd the surface area of a right cylinder by taking the radius value and height as input from the user.

Prob 2) Write a m n matrix with (i) all zero elements, (ii) all elements as 1 and (iii) having all 1’s in the diagonal and rest of the elements are zero’s.

Prob 3) Write a Matlab code to nd the largest and smallest element of an array of order m n and their positions.


Prob 4) Consider the following system of three equations in matrix form
2
4  13
4
3 2x23
=
2 0 3
:

6
4
0
x1

4
2

4 0
4
7 5 4x35


35

Write a Matlab code to solve the above system by taking the coe cient matrix and right hand side constant vector from the user.

Prob 5) Write a Matlab code to take any value of n as input from the user. If n 5 then display \n is greater than or equal to 5", otherwise display \n is less than 5".

Prob 6) Write a Matlab code to addition of two m    n matrices.

Prob 7) Write a function to nd the factorial of a number and use it to calculate the ap-proximate value of e by using it’s Taylor’s series

e = 1 + 1!1 + 2!1 + 3!1 + ::::


with error of less than 0:001?

Prob 8) Given x = [3 1 5 7 9 2 6], explain what the following commands "mean" by sum-marizing the net result of the command.

a.) x(3)

b.) x(1 : 7)

c.) x(1 : end)

d.) x(1 : end

1)

e.) x(6 :

2:1)

f.) x([1 6 2 1 1])

g.) sum(x).

Prob 9) Given the array A = [ 2 4 1 ; 6 7 2 ; 3 5 9], provide the commands needed to

a.) assign the    rst row of A to a vector called x1.

b.) assign the last 2 rows of A to an array called y.

c.) compute the sum over the columns of A.

d.) compute the sum over the rows of A.

e.) compute the standard error of the mean of each column of A (NB. the standard error of the mean is de ned as the standard deviation divided by the square root of the number of elements used to compute the mean.)



Prob 10) Given the arrays x = [1 4 8], y = [2 1 5] and A = [3 1 6 ; 5 2 7], determine which of the following statements will correctly execute and provide the result. If the command will not correctly execute, state why it will not. Using the command whos may be helpful here.

a.) x + y b.) x + A c.) x’ + y d.) A - [x’ y’] e.) [x ; y’] f.) [x ; y] g.) A - 3.

Prob 11) Given the array A = [2 7 9 7 ; 3 1 5 6 ; 8 1 2 5], explain the results of the following commands:

a.) A’    b.) A(:,[1 4])    c.) A([2 3],[3 1])    d.) reshape(A,2,6)    e.) A(:)

f.)    ipud(A)    g.)    iplr(A)    h.) [A A(end,:)]    i.) A(1:3,:)    j.) [A ; A(1:2,:)]

k.) sum(A)    l.) sum(A’)    m.) sum(A,2)

p.) [ [ A ; sum(A) ] [ sum(A,2) ; sum(A(:)) ] ].

Prob 12) Give the following commands to create an array called F:

    • randn(’seed’,123456789)

    • F = randn(5,10);

a.) Compute the mean of each column and assign the results to the elements of a vector called avg.

b.) Compute the standard deviation of each column and assign the results to the elements of a vector called s.

c.) Compute the vector of t-scores that test the hypothesis that the mean of each column is no di erent from zero.

Prob 13) Given the vector x = [1 8 3 9 0 1], create a short set of commands that will

a.) Add up the values of the elements (Check with sum.)

b.) Computes the running sum (for element j, the running sum is the sum of the elements from 1 to j, inclusive. Check with cumsum.)

c.) computes the sine of the given x-values (should be a vector).




















2

More products