Matlab Sheet 1 Solution
Matlab Sheet 1 Solution
An Overview of MATLAB
In Command Window:
u=
13
v=
30
w=
3.3333
z=
0.1736
r=
0.4187
s=
0.5226
2. Suppose that x = 3 and y = 4. Use MATLAB to compute the following,
and check the results with a calculator.
1 −1 3𝑦 4(𝑦−5)
a. (1 − 𝑥 5 ) b. 3𝜋𝑥 2 c. d.
4𝑥−8 3𝑥−6
The m-file:
clc;clear
x = 3; y = 4;
1/(1-1/x^5)
3*pi*x^2
3*y/(4*x-8)
4*(y-5)/(3*x-6)
In Command Window:
ans =
1.0041
ans =
84.8230
ans =
3
ans =
-1.3333
3. Use MATLAB to calculate
3 45 48.2(55)−93 274 3194⁄5
a. 4 (6)(72 ) + 73 −145 b. c. + + 60(14)−3
53+142 4 5
The m-file:
clc;clear
a = (3/4)*6*7^2+4^5/(7^3-145)
b = (48.2*55-9^3)/(53+14^2)
c = 27^2/4+319^(4/5)/5+60*14^-3
In Command Window:
a=
225.6717
b=
7.7189
c=
202.4120
4. Use MATLAB to calculate
√412 −5.22 3 ln(500)
a. 𝑒 5 −100.53 b. √132 + 8
The m-file:
clc;clear
disp('Part (a)')
sqrt(41^2-5.2^2)/(exp(5)-100.53)
disp('Part (b)')
%alternative: nthroot(132,3)+log(500)/8
132^(1/3)+log(500)/8
In Command Window:
Part (a)
ans =
0.8493
Part (b)
ans =
5.8685
5. Define the variables a, b, c, and d as:
3𝑎 (𝑎−𝑏)𝑐
𝑎 = 12, 𝑏 = 5.6, 𝑐 = and 𝑑 = , then evaluate
𝑏2 𝑐
𝑑−𝑐
𝑎 𝑑−𝑐 𝑏
a. + 𝑑+𝑐 − (𝑑 − 𝑏)2 b. 𝑒 𝑎−2𝑏 + ln (|𝑐 − 𝑑 + 𝑎|)
𝑏
The m-file:
clc;clear
a=12; b=5.6; c=3*a/b^2; d=(a-b)^c/c;
disp('Part (a)')
a/b+(d-c)/(d+c)-(d-b)^2
disp('Part (b)')
exp((d-c)/(a-2*b))+log(abs(c-d+b/a))
In Command Window:
Part (a)
ans =
-0.1459
Part (b)
ans =
2.2925e+03
6. Evaluate the following expressions in MATLAB, for the values x = 5 + 8i,
y= -6 + 7i. Check your answers by hand.
a. u = x + y b. v = xy c. w = x/y
d. z = ex e. r =√𝑦 f. s = xy2
The m-file:
clc;clear
x=5+8i;
y= -6+7i;
u=x+y
v=x*y
w=x/y
z=exp(x)
r=sqrt(y)
s=x*y^2
In Command Window:
u=
-1.0000 +15.0000i
v=
-86.0000 -13.0000i
w=
0.3059 - 0.9765i
z=
-2.1594e+01 + 1.4683e+02i
r=
1.2688 + 2.7586i
s=
6.0700e+02 - 5.2400e+02i
7. Two trigonometric identities are given by:
3 tan 𝑥 − 𝑡𝑎𝑛3 𝑥
a. tan 3𝑥 = b. cos 4𝑥 = 8(𝑐𝑜𝑠 4 𝑥 − 𝑐𝑜𝑠 2 𝑥) + 1
1−3 𝑡𝑎𝑛2 𝑥
For each part, verify that the identity is correct by calculating the values of the
left and right sides of the equation, substituting 𝑥 = 24° .
The m-file:
clc;clear
a=12; b=5.6; c=3*a/b^2; d=(a-b)^c/c;
x=24;
disp('Part (a)')
%compare LHS and RHS
LHS = tand(3*x)
RHS = (3*tand(x)-tand(x)^3)/(1-3*tand(x)^2)
disp('Part (b)')
LHS = cosd(4*x)
RHS = 8*(cosd(x)^4-cosd(x)^2)+1
In Command Window:
Part (a)
LHS =
3.0777
RHS =
3.0777
Part (b)
LHS =
-0.1045
RHS =
-0.1045
8. Find the value for the following expressions
𝜋
a. 𝑎𝑟𝑒𝑎 = 4 (𝑑𝑜2 − 𝑑𝑖2 ) , 𝑑𝑜 = 100 mm , 𝑑𝑖 = 40 mm
𝜎𝑥 + 𝜎𝑦 𝜎𝑥 − 𝜎𝑦 2
b. 𝑠𝑡𝑟𝑒𝑠𝑠 = + √( 2
) + 𝜏𝑥𝑦 , 𝜎𝑥 = 100, 𝜎𝑦 = 80, 𝜏𝑥𝑦 = 52 MPa
2 2
The m-file:
clc;clear
do=100;
di=40;
area=(pi/4)*(do^2-di^2)
sx=100;
sy=80;
txy=52;
stress=((sx+sy)/2)+sqrt((((sx-sy)/2)^2)+(txy^2))
In Command Window:
area =
6.5973e+03
stress =
142.9528