2nd assignmentMATLAB-_MEE1006
2nd assignmentMATLAB-_MEE1006
Assignment-2
(Release Date: 3rd Dec 2024; Due Date: 10th Dec 2024)
Q.1 Write a MATLAB code using 𝑦 = 𝑥 2 − 1 to generate the plot of ‘𝑦’ shown in Figure 1 below.
Figure 1
Q.2 Suppose you have a matrix D of size 4 × 6 filled with consecutive integers starting from 1.
Create the matrix D in MATLAB and reshape matrix D into a 2 × 12 matrix. Write the code and its
output.
Q.3 Using the MATLAB built-in functions (zeros, ones, eye), create the following matrix
0 0 0 1 1
0 0 0 1 1
1 0 0 0 0
𝐴= 0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
[0 0 0 0 1]
1 2 3
Q.4 For the given matrix, A= [4 5 6] write the code and its output while perform the following
7 8 9
operations:
i) Delete first row of given matrix A
ii) Generate sub matrix B from given matrix A having any first and second rows
iii) Transpose of sub matrix B
iv) Calculate elemental square and square of matrix A
Page 1 of 2
Q.5 In MATLAB, plot the following functions in the same 2D plot within a range of [−2𝜋, 2𝜋].
Write the code and show its output.
(i) 𝑦1 = sin(𝑥)
(ii) 𝑦2 = cos(𝑥)
(iii)𝑦3 = tan(𝑥)
(iv) 𝑦4 = 𝑒 𝑥
(v) 𝑦5 = log(𝑥)
Q.6 Figure 2 shows the location of the centre of gravity of a 5000 N truck for the unloaded condition.
The location of the added load 𝑊𝐿 is at a distance of x inches behind the rear axle. Using MATLAB,
plot 𝑊𝐿 as a function of x, ranging from 0 to 60 mm with a step size of 0.05. Label the axis as 𝒙
(mm) and Load (N) and give the figure title as ‘Load vs Distance’.
Figure 2
From free body diagram, 𝑊𝐿 have been obtained as
5000
𝑊𝐿 =
60 + 𝑥
Q.7 Create an anonymous function in MATLAB named parabola that represents the equation
of a parabola. The parabola equation is given as:
Write MATLAB code to define the anonymous function parabola using these coefficients.
Then, use the function handle to evaluate the value of the parabola function at 𝑥 = 1. Redefine
this function by vectorizing the expression so that it can take array as an input. Create a vector
input 𝑥 ranging from -10 to 10 and generate a plot for this function. Write the code and show
its output.
Q.8 Write a MATLAB script to solve the following system of equations and write the code to verify
the solutions using symbolic substitutions:
𝑥 + 3𝑦 − 𝑧 = 2-------(1)
𝑥 − 𝑦 + 𝑧 = 3 -------(2)
3𝑥 − 5𝑦 = 4 -------(3)
Q.9 Using MATLAB differentiate, y(x) = 𝑒 −𝑥 sin(𝑥) symbolically. Also obtain the value of
𝑦 ′ (𝜋/2). Write the code and its output.
𝑚 2
Q.10 Using MATLAB compute the indefinite integral ∫0 𝑒 −𝑥 sin(𝑥) 𝑑𝑥 symbolically. Also
substitute ‘𝑚’ by ‘π’ and obtain the definite value. Write the code and its output.
Page 2 of 2