Lab Manual - MATLAB
Lab Manual - MATLAB
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
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”
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.
[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)
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
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
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
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