You are on page 1of 3

MIDDLE EAST TECHNICAL UNIVERSITY ME 208 DYNAMICS MATLAB NOTES Matlab Window: Matlab has three main windows

s namely Workspace, Command History and Command Window. Command Window is where you enter your command lines to do any operation. You can watch your previous commands on Command History and you can call one or a selection of them. You can access your variables defined in your workspace from the Workspace window. Definitions: Single variables can be created by directly assigning them a value: >> a = 10 Return values of a function can also be used to assign the first value: >> a = sin(pi/3) To define matrices the following format should be used: >> a = [1 2; 3 4] produces a matrix of a = 1 3 2 4

Defining a vector is similar. For a row and column vector: >> a = [1 2 3 4 5] >> b = [1;2;3;4;5] produces matrices of a = b = 1 1 2 3 4 5 If an independent variable like an angle or time is needed, an incremental series can be created by: >> theta = 0 : 0.1 : 359.9 which produces theta = 0 0.1 0.2 0.3 ... 359.9 2 3 4 5

Basic Operations: Basic operations can be listed as: Operation Addition Subtraction Multiplication Division Power Transpose Determinant Inverse Identity Matrix Syntax a+b a-b a*b a/b x^y a det(a) inv(a) eye(m,n) Matrix a.*b for term by term multiplication martix division (a/b and a\b differ) a.^b for term by term calculation

returns an identity matrix of size mxn

Some trigonometric and logarithmic fuction are: Fuction Sine Cosine Tangent Cotangent Arcsine Arcosine Arctangent Arccotangent Arctan2 Natural Logarithm Base 10 Logarithm Plots: Variables can be plotted by either right clicking the variable in workspace window and selecting plot 2d graph, or by using the commands: y only >> plot(y) y vs. x >> plot(x,y) Syntax sin(x) cos(x) tan(x) cot(x) asin(x) acos(x) atan(x) acot(x) atan2(x,y) log(x) log10(x)

Example: Recall the question 2.141 in HW1.

& = 0.6rad / s AB = CB = 150 mm


For instance we want to plot && as a function of r between 30 and 180. If we formulate it: CB & && = 2 .[2. AB. cos ] + AB. 2 .[cos . cos sin . sin ] r &

AB

>> beta = 30:0.5:180 >> beta = beta/180*pi >> teta = (pi-beta)/2 >> w = 0.6 >> AB = 150 >> CB = 150 >> tetadot = -w/2 >> rddot = tetadot.^2*(2*AB*cos(teta)) + AB*w^2*(cos(beta).*cos(teta)-sin(beta).*sin(teta)) >> plot(teta,rddot) These lines will produce a graph like:
-5

-10

-15

-20

-25

-30

0.2

0.4

0.6

0.8

1.2

1.4

You might also like