Professional Documents
Culture Documents
- Displays the list of variables currently in the memory. - Will display more details which include size, space, allocation and class of variables - Checks for existence of the variable. - Declares variable to be global. - Searches for help topic - Searches help entries for keyword - Stops the MATLAB
Displays the help document in the help function_name command window Displays the help document in helpwin function_name separate window doc function_name Displays detailed help document in separate window
Mathematical Functions
Special Variables and Constants
ans
i, j
Inf NaN pi
Mathematical Functions
Elementary Functions
cos(x) Cosine abs(x) Absolute value
sin(x)
tan(x)
Sine
Tangent
ceil(x)
floor(x)
acos(x)
asin(x)
Arc cosine
Arc sine
round(x)
rem(x)
Round
Remainder after division
atan(x)
exp(x) sqrt(x) log(x) log10(x)
Arc tangent
Exponential Square root Natural Logarithm
angle(x)
conj(x) imag (x) real (x) primes (x)
Phase
Complex Conjugate imaginary Real number Prime Number
Common Logarithm
Mathematical Functions
Scalar Arithmetic
Symbol + Operation Addition
* /
Subtraction
Multiplication Right Division
\
^
Left Division
Exponentiation
Mathematical Functions
Exponential and Logarithmic Functions
exponential
Natural Logarithm Common Logarithm Square root
exp (x)
ln (x) log10 (x) = [ log10 (x) ] sqrt (x)
Example1: 2+34 In Command Window >>2 + 3 4 ans = 1 Example2: 63 In Command Window >> 6 / 3 ans = 2
Example3: 36 In Command Window >> 6 \ 3 ans = 0.5 MATLAB has assigned the answer to a variable called ans, which is an abbreviation for answer. A variable in MATLAB is a symbol used to contain a value.
MATLAB does not care about spaces for the most part. Spaces in the line improve its readability. When you want to calculate a more complex expression use parentheses, in the usual way, to indicate precedence. The mathematical operations represented by the symbols + * / \, and ^ follow a set of rules called precedence..
Mathematical expressions are evaluated starting from the left, with the exponentiation operation having the highest order of precedence, followed by multiplication and division with equal precedence, followed by addition and subtraction with equal precedence.
Parentheses can be used to alter this order. Evaluation begins with the innermost pair of parentheses, and proceeds outward.
To avoid mistakes, you should feel free to insert parentheses wherever you are unsure of the effect precedence will have on the calculation. Example4:
When you write the semicolon ; at the end of a statement, the computer will not display the result of the command, and it will not echo the input. >>2*a ans = 4 >>w=3*A w= 9 MATLAB does not tell you the value of all the variables; it merely gives you their names. To find their values, you must enter their names at the MATLAB prompt.
>>a = 4 a= 4 >>2*a ans = 8 If you reuse a variable in the preceding example, or assign a value to one of the special variables, its prior value is overwritten and lost. However, any other expressions computed using the prior value do not change.
Example6: Given: = 30, = 52, = 76 Find: a. Sin b. Sin c. Sin In Command Window >> alpha = 30; >> beta = 52; >> gamma = 76;
>> sin (alpha) ans = 0.9880 A pair of parentheses is used after the functions name to enclose the value called the functions argument that is operated on by the function. >> sin (beta) ans = 0.9866 >> sin (gamma) ans = 0.5661
MATLAB remembered past information. To recall previous commands, MATLAB uses the cursor keys, , , , , on your keyboard. In addition, all text after a percent sign (%) is taken as a comment statement.
Example of Formating: or pi In Command Window >> pi ans = 3.1416 MATLAB uses high precision for its computations, but by default it usually displays its results using four decimal places. This is called the short format. Using the format command can change this default.
>> format long >> pi ans = 3.14159265358979 MATLAB uses the notation e to represent exponentiation to a power of 10. >> format short e >> pi ans = 3.1416e+000
>> format long e >> pi ans = 3.14159265358979e+000 >> format bank >> pi ans = 3.14 To return to default format >> format >> pi ans = 3.1416
Most interesting is the format rat: it yields a rational approximation of a real number, that is a fraction that approximates a given number. >> format rat >>pi ans = 355/113 >>format >>355/113 ans = 3.1416
e. Given: =
g. h. cos 2
1 0.3 cos
b. 3
1 1 1 5 2
3 48 4 5 36
3. Assuming that the variables a, b, c, d and f are scalars, write MATLAB statements to compute and display the following expressions. Test your statements for the values a = 1.12, b = 2.34, c = 0.72, d = 0.81, f = 19.83
a. = 1 + b. =
1
1 1 1 + + +
c. = 1
d. =
1 2 2
4.
Evaluate the following expressions MATLAB, for the values x = 5 + 8i, y = 6 + 7i. a. u = x + y b. v = xy c. w = x / y d. z = ex e. = f. s = xy2
in