Page 836 - Mechatronics with Experiments
P. 836
822 MECHATRONICS
>> y = rem(x,z) ; % Reminder function: y = x - fix(x/z)
>> y = sign(x) ; % returns 1 if x>0,0ifx=0, -1 if x< 0.
>> % Trigonometric functions
>> y = sin(x) ; % Sin function
>> y = cos(x) ; % Cosine function
>> y = tan(x) ; % Tangent function
>> y = cot(x) ; % Cotangent function
>> y = asin(x) ; % Arcsin (inverse Sin) function
>> y = sinh(x) ; % Hyperbolic sin function
>> y = asinh(x) ; % Inverse hyperbolic Sin function
% Similar functions for cos, tan, cot.
Polynomials, their roots, and multiplication of polynomials are handled by the coef-
ficients data vector. Let us consider a polynomial as follows:
n
a s + a s n−1 + a s n−2 + ⋯⋅ +a = 0 (A.1)
0 1 2 n
The roots of the polynomial can be found as follows
>> c = [ a_0 a_1 a_2 ... a_n] ; % Defines the coefficients of
the polynomial
>> r = roots(c); % r is the vector that has the roots of the
polynomial.
>> c = poly(r) ; % poly() does the opposite of roots() - -
given the roots,
% it calculates the coefficients of the
corresponding polynomial.
>> c3 = conv(c1, c2) ; % multiplies two polynomials, and
% returns the coefficients of the
resulting polynomial.
% (Length of c3) = (length of c1 + length
of c2-1)
>> y1 = interp1(x,y,x1); % given (x,y) vector pair,
% find interpolated value(s) of y1 at x1
% using linear (default) interpolation.
% If x1 is scalar, y1 is scalar. If x1
is vector, so is y1.
A.1.4 Input and Output in MATLAB ®
MATLAB ® has most of the features of a high level programming language, such as C,
plus the additional convenience of easily handling graphical plotting of data and automatic
declaration of data type. Unlike in C, the data type of a variable does not need to be declared
in advance of its usage. MATLAB ® automatically handles that. In any programming
environment, we need to be able to input–output the data to-and-from the program and
apply logic to it.
®
Data can be input to a MATLAB environment in one of the following ways:
1. From the keyboard, using “input” function.
2. From a previously saved “∗.mat” file, using “load.”