Anda di halaman 1dari 6

MATLAB ENGINEERING // SECOND YEAR//CHEMICAL ENG. DEPT.

Notes for working in the command windows

1. Once a command is typed and the Enter key is passed, the command is executed.
However, only the last command is executed. Everything executed previously is
unchanged.
2. Several commands can be typed in the same line. This is done by typing a comma
between the commands. When the Enter key is passed the commands are executed in
order from left to right.

a=
2
b=
3
c=
5
3. It is not possible to go back to previous line in the command window, make
correction, and the re-execute the command.
4. A previously typed a command can be recalled to the command prompt with up arrow
key ( . When the command is displayed at the command prompt, it can be modified
if need and executed. The down arrow key can be used to move down the
previously typed command.
5. The Semicolon (;):- when a command is typed in the command window and the
<enter> key is passed, the command is executed. Any output that the command
generates is displayed in the command window. If a semicolon is typed at the end of
the command the output of the command is not displayed. Typing a semicolon is
useful when the result is obvious or known, or when the output is very large.

7
MATLAB ENGINEERING // SECOND YEAR//CHEMICAL ENG. DEPT.

If a several commands are typed in the same line, the output from any of the
commands will not be displayed if a semicolon is typed between the commands
instead of a comma.
6. Typing %:- when the (percent symbol%) is typed in the beginning of the commands
or between the command, this has no effect on the execution of the command (%
represented as a comment only).
7. clc:- clear the command window.
clear:- Remove the variables from memory.

Numeric Display Formats


Format short Four decimal digits
format long (default).
16 decimal digits.
format short e Five digits plus
format long e 16
exponent.
digits plus
format bank exponents.
Two decimal digits.

Common Mathematical functions

Function Description Example


1 abs(x) |x|
ans=3
2 sqrt(x) √
ans=9.2195
3 nthroot(x,n) Find the real nth root of (x).
[If x is negative n must be ans=-1.2599
an odd integer].
4 sign(x) –1, x < 0
0, x = 0 ans=-1
1, x > 0
5 rem(x,y) the remainder of x /y » rem(23,6)
ans = 5

6 exp(x) x
e ans= 2.2026 e+004
8
MATLAB ENGINEERING // SECOND YEAR//CHEMICAL ENG. DEPT.

7 log10(x) log base 10 log 10 x


ans=1
8 log(x) natural log ln x
ans=2.3026
9 Factor(x) Find the prime factors of x
ans=2 2 3
Random integers

10 round(x) nearest integer » round(-5.5)


ans = -6
11 floor(x) nearest integer toward – » floor(-5.5)
(Largest integer less than or ans = -6
equal to x) » floor(5.5)
ans = 5
12 ceil(x) nearest integer toward+ » ceil (-5.5)
(Smallest integer greater than or ans=-5
equal to x)

13 Fix(x) nearest integer equals floor(x) if x » fix(-5.5)


is positive and ceil(x) if x is ans =-5
negative

Trigonometric math Functions


14 sin(x) (x in radians) sine of angle x » sin(pi/6)
ans=0.500
sind(x) (x in degree) sind(30)
ans=0.500
15 cos(x) (x in radians) cosine of angle x » cos(pi/2)
ans=0
cosd(x) (x in degree) sind(30)
ans=0.500
16 tan(x) (x in radians) Tangent of angle x » tan(pi/6)
ans=0.5774
tand(x) (x in degree) sind(30)
ans=
17 cot(x) (x in radians) cotangent of angle x » cot(pi/6)
ans=

9
MATLAB ENGINEERING // SECOND YEAR//CHEMICAL ENG. DEPT.

cotd(x) (x in degree) cotd(30)


ans=1.7321
The invers of trigonometric math Functions
18 asin(x), acos(x), atan(x), acot(x) for the angle in radians
asind(x), acosd(x), atand(x), acotd(x) for the angle in degree
The hyperbolic trigonometric functions
19 sinh(x), cosh(x), tanh(x), coth(x)
Variables

Variables can be named according to the following rules:-

1.It may consist only of the letters a– z, the digits 0–9 and the underscore (_)., (can not
contain punctuation characters (eg. Period, comma, semicolon).

2. It must start with a letter.


3. MATLAB is case sensitive, which means it distinguishes between upper- and lowercase
letters. So balance, BALANCE and BaLance are three different variables.
4. Avoid using the name of a built- in function for variables (i.e avoid using cos, sin, exp,
sqrt,etc).
5. A number of frequently used variables are already defined when Matlab is started.Some
of predefined variables are listed in table below:-

Special constants and variables

ans Most recent answer.


eps Accuracy of floating-point precision.
i,j The imaginary unit - 1.
Inf Infinity.
NaN Undefined numerical result (not a number).
pi The number p .

Example:

<enter>
z=3.000+4.000i
<enter>
ans=3
10
MATLAB ENGINEERING // SECOND YEAR//CHEMICAL ENG. DEPT.

<enter>
ans=4

ans=0.9273, where the rule of

ans=5, where √

ans=5.000+7.000 i
Example:- translate the equation of angle in Matlab commands
( )
angle=0.9273
Exercises
1-Write a program to convert a given temperature from (F) to (C).
2- Write a program to calculate the vapor pressure of water according to Antoine equation

,A=18.3036,B=3816.44,C=-46.13

3- For the following distillation column. Write a code to find the value of steam B and the
composition of steam D? D=80 , % X?,%S?,%T?,%Z?

F=100kg

15% X

25%S

40%T

20%Z B=? , 15% X,25%S,40%T,20%Z

11
MATLAB ENGINEERING // SECOND YEAR//CHEMICAL ENG. DEPT.

4- The distance (d) from a point (3,-4) from the line 2x-7y-10=0.(use the abs and sqrt
commands).
5- Calculate the following:-


( ) ( )

( )
( )

12

Anda mungkin juga menyukai