0% found this document useful (0 votes)
18 views3 pages

Octave Matlab Tutorial Part1 Essentials

Uploaded by

Usha Arcelia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views3 pages

Octave Matlab Tutorial Part1 Essentials

Uploaded by

Usha Arcelia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

66 Chapter 2 Getting Started with MATLAB

Problems

Which of the following are legitimate variable names in MATLAB? Test your answers
by trying to assign a value to each name by using, for example,
3vars = 3

or by using isvarname, as in
isvarname 3vars

Remember, isvarname returns a 1 if the name is legal and a 0 if it is not.


1. 3vars

2. global

3. help

4. My_var

5. sin

6. X+Y

7. _input

8. input

9. tax-rate

10. example1.1

11. example1_1

12. Although it is possible to reassign a function name as a variable name, it is


not a good idea, so checking to see if a name is also a function name is also
recommended. Use which to check whether the preceding names are
function names, as in
which cos

Are any of the names in Problems 1 to 11 also MATLAB function names?

Predict the outcome of the following MATLAB calculations. Check your results by
entering the calculations into the command window.

13. 5-2*6+8^2/4*3*2

14. 5*6*4/2

15. 5/2*6*4

16. (6*6+8^2-4*5*5)/(3*7-2*5*2-1)

17. 5^(2*3)

18. 9*2^4^2*7

19. (6*3+8^2)/(4^2+2*10-18*2)

M02_ETTE9390_03_GE_C02.INDD 66 21/11/14 3:57 PM


Problems 67

Write simple MATLAB programs for evaluating the following mathematical


expressions. The values of the variables n, x, y, and z are to be entered by
the user.
20. (xy)z + 23 x
21. x = 2y 2 + z 2
ny ny 2 ny 3
22. x = 12 + 22 + 33
23. If two points on a coordinate plane are input by the user, write a MATLAB
(y 2 - y 1)
program to calculate the slope of the line. [Slope = (x 2 - x 1) ]
24. Create a MATLAB code to perform the following calculation.
1 + 5 * 3/62 + 22-4 * 1/5.5
Check your code by entering it into MATLAB.
25. The area of a circle is pr 2. Define r as 5, and then find the area of a circle.
26. The surface area of a sphere is 4pr 2. Find the surface area of a sphere with
a radius of 10 ft.
27. The volume of a sphere is 43pr 3. Find the volume of a sphere with a radius
of 2 ft.
28. The volume of a cylinder is pr 2h. Define r as 3 and h as the matrix
h = [1,5,12]
Find the volume of the cylinders.
29. The area of a triangle is ½ base * height. Define the base as the matrix
b = [2,4,6]
and the height h as 12, and find the area of the triangles.
30. The volume of a right prism is base area * vertical dimension. Find the
volumes of prisms with triangles of Problem 29 as their bases, for a vertical
dimension of 10.
31. Generate an evenly spaced vector of values from 1 to 20, in increments of 1.
(Use the linspace command.)
32. Generate a vector of values from zero to 2p in increments of p>100. (Use
the linspace command.)
33. Generate a vector containing 15 values, evenly spaced between 4 and 20.
(Use the linspace command.)
34. Generate a table of conversions from degrees to radians. The first line
should contain the values for 0º, the second line should contain the values
for 10º, and so on. The last line should contain the values for 360º.
35. Generate a table of conversions from centimeters to inches. Start the centi-
meters column at 0 and increment by 2 cm. The last line should contain the
value 50 cm.
36. Generate a table of conversions from mi/h to ft/s. The initial value in the
mi/h column should be 0 and the final value should be 100. Print 14 values
in your table.
37. The general equation for the distance that a free falling body has traveled
(neglecting air friction) is
d = 12gt 2
Assume that g = 9.8 m/s2. Generate a table of time versus distance traveled,
for time from 0 to 100 s in increments of 10 s. Be sure to use element-by-element
operations, and not matrix operations.

M02_ETTE9390_03_GE_C02.INDD 67 21/11/14 3:57 PM


68 Chapter 2 Getting Started with MATLAB

38. Newton’s law of universal gravitation tells us that the force exerted by one
particle on another is
m 1m 2
F = G
r2

where the universal gravitational constant is found experimentally to be


G = 6.673 * 10-11Nm2 >kg 2
The mass of each object is m 1 and m 2, respectively, and r is the distance
between the two particles. Use Newton’s law of universal gravitation to find
the force exerted by the Earth on the Moon, assuming that:
the mass of the Earth is approximately 6 * 1024 kg,
the mass of the Moon is approximately 7.4 * 1022 kg, and
the Earth and the Moon are an average of 3.9 * 108 m apart.
39. We know the Earth and the Moon are not always the same distance apart.
Find the force the Moon exerts on the Earth for 10 distances between
3.9 * 108 m and 4.0 * 108 m.

Matrix Analysis
Create the following matrix A:
3.4 2.1 0.5 6.5 4.2
A = £ 4.2 7.7 3.4 4.5 3.9 §
8.9 8.3 1.5 3.4 3.9
40. Create a column matrix B by extracting and transposing the third row of
matrix A.
41. Create a matrix C by extracting the second row of matrix A.
42. Create a row matrix D of five elements between 1 and 9 using linspace
command.
43. Create a matrix F by extracting the values in columns 2, 3, and 4, and com-
bining them into a single column matrix.
44. Create a new matrix M by combining the matrices C' and D'.

M02_ETTE9390_03_GE_C02.INDD 68 21/11/14 3:57 PM

You might also like