You are on page 1of 9

Exercise 1 : Basic Matlab Practice

1. Consider matrix
A=[ 1 3 5 7
5 9 23 12
8 34 22 87
56 43 4 63]
Prepare a script file for the following

(a) Store 2nd row in “b”


(b) Store 3rd column in “c”
(c) Store all the elements of 2nd row from 2nd column till the end.
(d) Store all the elements of 3rd column from 3rd row till the end.
(e) Find transpose of the matrix A
(f) Find inverse of the matrix A
(g) Determine number and rows in the matrix A and display it on the screen.

2. Consider the two matrices:


A = [ 1 0 1; 2 3 4; -1 6 7]
B=[ 7 4 2; 3 5 6; -1 2 1]
Using MATLAB, determine the following (prepare script file):
(a) A + B
(b) AB
(c) A2
(d) AT
(e) B–1
(f ) BTAT
(g) A2 + B2 – AB
(h) determinant of A, determinant of B and determinant of AB.

3. Determine the Eigen values and Eigen vectors of the matrix A and B.

4. Determine the values of x1, x2 and x3 for the following set of linear algebraic equations:
x2 – 3x3 = –5
2x1 + 3x2 – x3 = 7
4x1 + 5x2 – 2x3 = 10

5. Prepare a script file to take unknown as variables and gives output of the following expression.
Exercise 2: If-else, switch command

1. Prepare a Matlab program which takes input as marks and displays grade as per the
following scheme:

Grade Marks
AA >90
AB 81-90
BB 72-80
BC 64-71
CC 56-63
CD 48-55
DD 40-47
FF <40

2. Prepare a Matlab program which requires 1,2 3,4 or 5 as input and displays
“You have entered 1” if input is ‘1’
“You have entered 2” if input is ‘2’
“You have entered 3” if input is ‘3’
“You have entered 4” if input is ‘4’
“You have entered 5” if input is ‘5’
“Input invalid - Enter 1,2,3,4, or5”

3. Prepare a Matlab program which requires a,b,c,d or e as input and displays


“Acceleration” if input is ‘a’
“Buoyancy” if input is ‘b’
“Crank” if input is ‘c’
“Drill” if input is ‘d’
“Efficiency” if input is ‘e’
“Input invalid - Enter a,b,c,d or e”
4. Prepare a Matlab program which takes shaft diameter and dynamic load carrying capacity
as input.
-based on shaft diameter and dynamic load carrying capacity it should display the
appropriate bearing.
-it should display “invalid input- enter shaft diameter between 25 and 35 mm” if input
diameter is out of range.
- It should display “No bearing possible if dynamic capacity is out of range.
Exercise 3: for, while command
1. Prepare a Matlab program which gives square of numbers from 1 to 20 and display
number and its square on the screen.

2. Prepare a program which terminates at ‘a’<=0.001. Consider initial value of ‘a’ as 100
and it decreases by 1% in each iteration. Display values of ‘a’ at each iterations.

3. In example 2 terminate program in 10 iterations.

4. Prepare following matrix using ‘for’ statement.

[1 2 3 4….10
11 12 13 14…20
.
.
91 92 93 94…100]

5. Obtain the variation of Torque (T) with respect to diameter (D) for a shaft.
π
T= τD 3
16
Consider 10<=D<=100, τ=150 MPa.

6. Obtain variation for the following expression for 0.1<d<10 and D=[10 20 30 40 50]
Exercise:4 Plot

For all the plots indicate axis labels, chart title, legends wherever required)

1. Plot for Example:1 of Exercise 3


2. Plot for Example:5 of Exercise 3
3. Plot for Example:6 of Exercise 3
4. Obtain Surface plot and contour in different script files for (take n=2)

n
f ( x) = ∑ xi2
(1) i =1

− 100 ≤ xi ≤ 100,

n n
f ( x ) = ∑ xi + ∏ x i
(2) i =1 i =1

− 100 ≤ xi ≤ 100,

5. Obtain surface plot and contour plot in single figure using Subplot
2
n  i 
f ( x) = ∑  ∑ x j 
i =1  j =1 
− 100 ≤ xi ≤ 100

6. Obtain subplot in following form

2 3
n −1

1.
[
f ( x) = ∑ 100( xi +1 − xi2 ) 2 + ( xi − 1) 2 ]
i =1

− 30 ≤ xi ≤ 30

2.
f ( x) = ∑ ixi4 [ ]
i =1

− 1.28 ≤ xi ≤ 1.28

( ( x ))
30
f ( x) = −∑ xi sin i
3. i =1

− 500 ≤ xi ≤ 500

7. Obtain subplot in following form

2
1

1.
[
f ( x) = ∑ xi2 − 10 cos(2πxi ) + 10 ]
i =1

− 5.12 ≤ xi ≤ 5.12
n  1 30 2   1 30 
f ( x) = ∑ − 20 exp − 0.2 ∑ x − exp ∑ cos 2πxi 
2.  30 i =1 
i
 30 i =1 
i =1 
− 32 ≤ xi ≤ 32
n
f ( x) = ∑ [xi + 0.5]
2

3. i =1

− 100 ≤ xi ≤ 100
Exercise 5 to 10: CAD Problems

Exercise 5: Write a generalized code to generate a line between the given two end points using
DDA line algorithm (accommodate all the four + four conditions as discussed in the theory
class).

Exercise 6: Write a generalized code to generate a line between the given two end points using
Bresenhams’ algorithm.

Exercise 7: Write a generalized code to generate a circle for a user specified radius and
coordinates of center point.

Exercise 8. Write a generalized code to perform a 2D translation on user specified points (For
line, triangle, and quadrilateral). Plot the figures before and after transformation.

8a. Demonstrate Scaling, Reflection and Rotation about the coordinate axes.

Exercise 9: Write a generalized code to perform a 2D Rotation about an user specified point on
user specified entities (For line, triangle, and quadrilateral). Plot the figures before and after
transformation.

Exercise 10. Write a generalized code to demonstrate that the 3D Rotation is not commutative.
Use a simple rectangular parallelepiped to prove the same by plotting the results.
Exercise 11: Design Problems
1. Develop a Matlab program with following details:
Design problem: Shaft
Input parameters: Power (KW), rpm of shaft, Allowable shear stress, factor of safety,
length of shaft
Output: diameter of shaft, weight of shaft.

2. Develop a Matlab program by assuming same data as in problem 1 to find the material
saving if hollow shaft is used instead of solid shaft

3. Develop a Matlab program to design a cotter joint with following details:


Input: Material properties, load applied on cotter joint (tension and compression), factor
of safety for different parts
Output: All dimensions of cotter joint

4. Develop a Matlab code for the following data:


Objective: Selection of single row deep groove ball bearing
Input data: Radial load, axial load, expected life in hours, diameter of shaft
Output: Bearing designation
Exercise 12: FEA
1. Develop a Matlab code to solve following FEA problem:

Input: Material property, cross sectional area, load P1 and P2, length of each section
Output: Stress and deflection at point 1 ,2 and 3.
Assume : Number of element =3

P1 P2

3
2
1

2. Develop a Matlab code to solve the above problem with 6 elements and display the difference in
results

You might also like