Matlab test I feedback PDF

Title Matlab test I feedback
Author bilal sarwar
Course Control of Engineering Systems
Institution University of Hertfordshire
Pages 8
File Size 308.1 KB
File Type PDF
Total Downloads 70
Total Views 139

Summary

Matlab test I feedback...


Description

! ! 7ENT1074 Control of Engineering Systems MATLAB Phase Test I (2017-18) Solution notes This note provides some feedback on and explanations of the solutions for MATLAB phase test I (2017-18). 1. Given some data evaluate the following MATLAB expressions: a. b. c.

d.

e. ! Solution: This questions tests your appreciation of BODMAS and writing out the expressions with suitable use of *, /, and parenthesis ( ), to solve the problems. The code below would be one way to correctly calculate the expressions: a.

2*A + sqrt(B*C)+D/E

b.

F*(A*B^2+C^4)

c.

D*F / (A/B*(28+E))

d.

A*factorial(C)-D^(1/C)*E^(1/B) / (F/(2*E))

e.

abs(-A*E*D)*B^(1/3) + B*F*sqrt(A/F + B/C – exp(C/D))

<

! ! 2. State (using a 0 for false and a 1 for true) the validity of the following statements: Solution: i. The mod function performs the modulus of a number and has nothing to do with the properties of a given file. ii. The dot product is effectively the scalar product of two vectors. In MATLAB it is done using the function dot. The use of .* is to do with element-wise multiplication. iii. Yes, MATLAB follows the BODMAS approach to evaluating expressions. iv. Yes, A’ is the conjugate transpose, but will give the same as the regular transpose for non-complex numbers. v. To supress output in MATLAB the semi-colon operator (;) is used. vi. The operator / performs right handed division whilst \ performs left handed division. Therefore, the two expressions will give the same solution. vii. Valid MATLAB variables cannot start with a number. viii. The command A(2,3) will find the element in A on the second row and third column. ix. The function cross performs the cross product of two vectors, which is normally denoted as 𝐴×𝐵. x. There is no function average in MATLAB. To find the mean use the function mean. <

2 of 8

! ! 3. Find the element-wise solutions to the following: a. b. c.

x + 2y y x √ x

d.

5 X

xy

y+x

xi

i=3

e.

6 Y

x i · yi

i=2

!

Solution: This question tests your ability to correctly use the element-wise operators (e.g. .*, ./, .^): a.

x + 2.*y

b.

x.^y

c.

sqrt(x.*y).*x./(y+x)

d.

sum(x(3:5))

e.

prod(x(2:6).*y(2:6)) <

4. Find the following: a.

Subtract the element in the third row and fourth column of A from the element in the second row and first column of B: Solution: ans = B(2,1) – A(3,4)

b.

The sum of all the elements in A: Solution: ans = sum(sum(A))

c.

The first element of A

−1

B

Solution: ans = A\B; ans = ans(1); d.

Calculate the standard deviation of the data in the second column of B

3 of 8

! ! Solution: ans = std(B(:,2)) e.

Compute [B|A] then find the median of the third row

f.

Solution: ans = [B,A]; ans = median(ans(3,:)) ! Find the mean of the sum of the first, second, and fourth columns of A. Solution: ans = mean(sum(A(:,[1,2,4]))) <

5. For each of the problems stated below, state which of the following solutions is correct: a.

b.

c.

d.

Solution: As with Q2, this questions tests your appreciation of BODMAS and writing out the expressions with suitable use of *, /, and parenthesis ( ), to solve the problems. The code below would be one way to correctly calculate the expressions: a.

sqrt(abs(A+B*C^2)) / (4 + 5*D)

b.

(D/2)^(sqrt(B^C))

c.

factorial(B*D/100) + (B/C)/(A/D) + A^(B/2)

d.

( (B + C*B^2) / (25*A + tan(D^(1/3))) )^(1/5) <

4 of 8

! ! 6. What would you expect the value of x to be after running the following MATLAB code? Solution: This question tests your ability to interpret MATLAB code. If you are not comfortable doing this then you could simply copy the code into MATLAB and evaluate the statements. < 7. State (using a 0 for false and a 1 for true) whether each of the following MATLAB commands would produce the following plot:

Solution: This question tests your ability to interpret MATLAB code. If you are not comfortable doing this then you could simply copy the code into MATLAB and evaluate the statements. <

5 of 8

! ! 8. Evaluate the following function over 20 seconds

and determine the following: a. b. c. d. e.

The maximum value of y. The time period of oscillation, in seconds. The frequency of oscillation, in radians/second. The damping ratio The natural frequency, in herts.

Solution: This question can be solved graphically, or if you are familiar with modal analysis, with a set of known equations. Firstly, create a vector for t and then calculate the expression for each value of t. The plot t against y and inspect the plot. For example: a = 10; b = 5.5 T = 0:0.01:20; y = 1 – cos(a*t)*exp(-b*t); plot(t,y) Inspect the plot to get the maximum value of y (part a.) and the time period (part b.) The frequency of oscillation (part c.) is related to the time period by the expression 𝜔=

2𝜋 . 𝑇

The damping ratio (part d.) can be found using the logarithmic decrement method 𝜁=

𝛿 𝑥5 ,,,,,where,,,,,𝛿 ≜ ln , 𝑥6 2𝜋

and 𝑥5 and 𝑥6 are successive data points separated by the time period (e.g. successive peaks/troughs in the response). Lastly, the natural frequency (part e.) can be found by the expression 𝜔 . 𝜔8 = 1 − 𝜁6 However, the question asks for the frequency in Herts (Hz), so it needs to be converted to the correct unit: 𝜔 1 𝜔 , rad/s 𝑓8 , Hz = 8 = 2𝜋 1 − 𝜁6 2𝜋 <

6 of 8

! ! 9. Find the settling time (the time when the value is within 2% of the steady state value) for the system with the roots s, noting that

Solution: Again, you can make a plot of x against t and note the settling time graphically. For example s(1) = -3.5 + j*5.2; s(2) = -3.5 – j*5.2; T = 0:0.01:10; x = exp(s(1)*t) + exp(s(2)*t); plot(t,x) < 10. State (using a 0 for false and a 1 for true) the validity of the following statements: Solution: i. You can also write control flow statements directly in the main workspace, it’s just a lot harder to edit them there. ii. A switch statement can be used to evaluate both numerical cases (e.g. 0, 1, 2) or strings (e.g. ‘default’, ‘unstable, ‘stable’, etc.) iii. The break command exists a continuous loop before the normal exit conditions are met. The nature of IF loops and SWITCH statements makes such a command needless. iv. MATLAB scripts run just as if you had typed it into the main workspace. Thus, they make use of existing variables in the main workspace. Functions are selfcontained so the only variables that the code in a function has are those created in it, or those passed to it as inputs. v. IF loops and SWITCH statements allow you to check for values or conditions of variables, and run certain code based on these. FOR loops will run a set of code repeatedly until all the iterations have been run, and WHILE loops will run a set of code repeatedly until the specific exit conditions are met. vi. SWITCH loops evaluate the values of variables (numerical or string). IF loops evaluate conditional expressions. vii. Valid MATLAB variables cannot start with a number.

7 of 8

! ! viii. A FOR loop will run a set of code repeatedly until all the iterations have been run. In contrast, an IF loop will run certain code once that is associated with specific relational conditions of the variables being tested. ix. The function plotyy allows you to create a plot with two separate ordinates. x. WHILE loops will run a set of code repeatedly until the specific exit conditions are met.

8 of 8...


Similar Free PDFs