Uploaded by Earl Reyes

LABORATORY WORK 1 Exercises 1 and 2

advertisement
Laboratory Work#1
Introduction to Matlab
LABORATORY WORK #1
Introduction to MATLAB
EXERCISE 1
1. Enter the following commands on separate lines in the command window.
(i) r = 4
(ii) ab1 = 7.1 + 3.2
(iii) r
(iv) A = r∧2
(v) sol = ab1∗(1 + 1/r) (vi) ab1 = sol∧ (1/2)
(vii) CV2 = 10/3
(viiii) x = 1.5e-2
(ix) y = 41e7
(x) z = r/A
(xi) >>format rat
(xii) z
2. Enter one or more of the previous commands on the same line using a semi-colon ; to terminate
each command. Notice how the semi-colon may be used to suppress output.
Note: Suppress the output means the result calculated and stored in the variable but its
output doesn’t show in the command window.
3. Enter the following commands
>> format rat
>> a = 2; b = 3; c = 4;
>> a*(b+c)
>> a*b+c
>> a/b+c
>> a/(b+c)
>> Find thr longest side of a right-angle triangle is
4. Clear the variable b only.
EXERCISE 2
1. Find the longest side of a right-angle triangle whose other sides have lengths 12 and 5. Use
Pythagoras: (a2 + b2 = c2).
2. Find the roots of the quadratic equation 3x2 − 13x + 4 using the formula x = (−b ± √ b2 −
4ac)/2a. Calculate each root separately. Note that arithmetic expressions with an implied
multiplication such as 2a are entered as 2∗a in Matlab.
3. Given a triangle with angle π/6 between two sides of lengths 5 and 7, use the cosine rule (c2
= a2 + b2 − 2ab cos C) to find the third side. Note that π is available in Matlab as pi.
4. Determine the value of the expression a(b + c(c + d))a, where a = 2, b = 3, c = −4 and d = −3.
5. Use MATLAB to calculate the expression
where a = 3, b = 5 and c = −3.
Laboratory Work#1
Introduction to Matlab
IV. DATA AND RESULTS
Print out / screen shot your exercises result then paste below.
Note: Input first your complete name and year & section in the command line before you
execute each exercise. See example below:
EXERCISE 1
1.
2.
3.
4.
EXERCISE 2
1.
2.
Laboratory Work#1
Introduction to Matlab
3.
4.
5.
VI. CONCLUSION
(Your conclusion must be related to the objectives of this laboratory activity.)
Laboratory Work#1
Introduction to Matlab
VII. GUIDE QUESTIONS
1.
2.
3.
4.
5.
List down the commands that you found very useful in this laboratory work.
What are you going to do suppress each command?
How to easily recall commands in MATLAB?
How would you insert a comment in MATLAB?
What is the difference between clc and clear command?
Download