Professional Documents
Culture Documents
Introduction To MATLAB
Without passion you dont have energy; without energy you have nothing.
Question 1:
1. If y has not been assigned a value, Will MATLAB allow you to define the equation x = y ^2
to store in memory for later use?
2. If the volume of a cylinder of height h and radius r is given by V = r2h, use MATLAB to
find the volume enclosed by a cylinder that is 12 cm high with a diameter of 4 cm.
3. Display the results of sin (/4), sin (/3), and sin (/2) as rational numbers. Also consider
the phase as degrees.
4. Compute ex for a few values of x. You must take minimum 20 values and take the input
as vectors.
Question 2:
Solve the following set of linear equations; also find the determinant of each of the following
3x 2y 5
6x 2y 2
x 2y z 3
5y z 2
3x 2y z 7
4y z 2
3x 2y 9z 65
9x + 5y 2z 16
6x 7y 3z 5
x 2y 3z = 12
4x y 2z = 13
9y 8z = 1
HITEC UNIVERSITY
x 2y 3z = 1
x 4y 3z = 2
2x 8y z =
x 7y 9z = 12
x y 4z = 16
x y 7z = 16
2w + 4x - 3y + 29z =20
12w + 8y + 2z =10
-5w + x + 10z =40
w +x + y +z =20
5x 2y 9z 44
9x 2y 2z 11
6x 7y 3z 44
Question 3:
Discuss the different format types used in MATLAB. Please write in your own words and it must
not exceed more than 5-lines.
Question 4:
Explain with examples how to add rows and columns in a defined matrix
Note: you are advised to take row vector, column vector and 2-D, 3-D vectors respectively
------------------------------------------------------------------------------------------------------------------
HITEC UNIVERSITY
Note: you must label each and every plot, which includes xlabel, ylabel grid, title and
legend
Question 5:
1. Y=cos(x)
2. Y=sin(x)
3. Z=Tan(x)
4. Y=ex + tanh(x)
5. Y=sin-1(x+2)
6. Y=tanh-1(x+8)
7. Y= ex .sin(x)
8. Y=sin(x).cos(x)
9. Y=tan(x)+2ex
10. Y=e-x
HITEC UNIVERSITY
Question 6:
Repeat Question 5 using stem command
Question 7:
Use the functions given in Question 5; plot multiple functions on same figure,
Question 8:
Plot the function Y= cos (T) for the following input vectors, also discuss its effects on the output
plot:
1. T=[0:100];
2. T=[0:0.1:100];
3. T=[0:0.001:100];
Question 9:
Generate a plot of following functions use axis command to adjust the limits:
Question 10:
Use the subplot command to display the multiple functions on same plot. You can use the
functions given in Question 5.
HITEC UNIVERSITY
Color Table
-----------------------------------------------------------------------------------------------------------------
HITEC UNIVERSITY
Use the Relational Operators given in the table and solve the following questions:
Question 11:
1. Predict and check the result of each of the operations given in above table for b = 0 and c
= -1.
2. Predict and check the result of each logical operator for b = [2 31 -40 0] and c = 0.
3. Define two random vectors (randn(1,7)) and perform all logical operations, including xor,
any and all.
Question 12:
a) x>y
b) y<x
c) x == y
d) x <= y
e) y >= x
f) x|y
g) x & (~y)
h) (x > y) | (y < x)
i) (x > y) & (y < x)
HITEC UNIVERSITY
Question 13:
Let x = 1 : 10 and y = [3 5 6 1 8 2 9 4 0 7]. The exercises here show the techniques of logical-
indexing. Execute and interpret the results of the following commands:
Question 14:
In each of the following questions, evaluate the given code fragments. Investigate each of the
fragments for the various starting values given below. Use Matlab to check your answers (be
careful, since those fragments are not always the proper Matlab expressions)
Part A:
if n > 1
m=n+2
else m = n - 2
end
a) n = 7 m = ?
b) n = 0 m = ?
c) n = -7 m = ?
Part B:
if s <= 1
t = 2z
elseif s < 10
t=9-z
elseif s < 100
t = sqrt(s)
else
t=s
end
Let z=20;
a) s = 1 t = ?
b) s = 7 t = ?
c) s = 57 t = ?
HITEC UNIVERSITY
d) s = 300 t = ?
Part C:
if t >= 24
z = 3t + 1
elseif t < 9
z = t^2/3 - 2t
else
z = -t
end
a) t = 50 h = ?
b) t = 19 h = ?
c) t = -6 h = ?
d) t = 0 h = ?
Part D:
if 0 < x < 7
y = 4x
elseif 7 < x < 55
y = -10x
else
y = 333
end
a) x = -1 y = ?
b) x=5y=?
c) x = 30 y = ?
d) x = 56 y = ?
Question 15:
Create a script that asks for a number N and computes the drag coefficient C, depending on the
Reynolds number N (make use of the if ... elseif ... construction). The command input might be
useful here (use help if needed).
HITEC UNIVERSITY
Check whether your script works correctly. Compute the drag coefficient for e.g. N = -3e3, 0.01,
56, 1e3, 3e6.
Question 16:
Write a script that asks for an integer and checks whether it can be divided by 2 or 3. Consider all
possibilities, such as: divisible by both 2 and 3, divisible by 2 and not by 3 etc (use the command
rem).
Question 17:
Write a script that asks for a temperature in degrees Celsius tc and computes the equivalent
temperature in degrees Fahrenheit tf (use the formula tf = 9/5 - tc + 32). The script should keep
running until no number is provided to convert. The functions input and isempty (use help to learn
more) should be useful here
Question 18:
Explain the purpose of following commands:
Diary, eye, magic, rank, linspace, fplot, mesh, surf, contour, surface
Bonus Question
GOOD LUCK
The single biggest problem in communication is the illusion that it has taken place.