You are on page 1of 87

‫ااد م

ن ذب‬

‫ﺍﻋﺪﺍﺩ‬

‫ﻋﺼﺎﻡ ﺳﺮﺣﺎﻥ ﺫﻳﺎﺏ‬

‫‪1‬‬
‫ااد م ن ذب‬




   
   
   
!" #$ % & ' &  
.(
   #$ % )   (   ( *  #$ +

 1 Matrix Laboratory &-" .


 /  0 MATLAB  " ,
"- 2 .") ,3 
4 $
' 5


6 +  7 !- 8 $
'
0$
' 4 ") # : a * b  % 6 .$
' .") ") #  #$ 4$5 4
b6
a .

:   7 ;  0
  6 %<
 0
  7" 
 * 0 #- 
  =" .>   0
 7 0 "" ? #$ ( 0 & =- 4 "-$
 7" 
 * !-  $
' A .*@ .") !
"     ' 6
.") 0 (" % -  ("-  < 
 #$ ) ,'
 B"-  ( ('" %-
 ( 5 /" #$    0  - !  $ ( /
.
 % 

!
0 '" E
 ! #$ 2 ) 0 +? Math Works C D> 0 #
 * 
.#=
 # ( 2")
 2 #$ %6 2( 
  # 4 !@
! !6 ?  - !@ 0 &  ) E
 !  #$  <   0 2
: X + 2Y = 24 12X – 5Y = 100
(  0 -
 - ") < > $
'   > #4 ,'5 !6 & =- !@ 0 <

.
- C B

,
B
$ !
 &C
+? 2"- 
 E
 0  -" #  .")   B  #$ < :

  0
   66 
 :% 6 .%   *@
4 +
 =) !


.# "  +
   
! 0  !6
!" "- 
= (: 5  B
) #  *
 *
!4' !) * +?  % 6$ B   & )= % -  2"  -
Algebric Equations   5 - ! 
= 2
Integration !
differentiation
 
- 0 !  #
"-   Differential Equations "4' 5 - 2

#@<   ") !- 


=
#@<  !4' !) * +? ! 2 ?=$ I !
 0   "= J? ("- % %
<" #


(Partial fraction
  !6  ( 5  + #$ !- * +?$ =?  0    

  2
Mechanical Field,  !  #$
Control System,
1
 E$ 
0? !  2
Automotive Industry,  )
Electronics

2
‫ااد م ن ذب‬
. ( =? 0 6
Aerospace and Defense,

 * IK /-



 /" ! 2 #6

 /"
!
 0C * I; 

0 C - #$ % ) 0C) 0 6 Computer Science  


")
4 >

.

 -

' -
Intel Hypercube 
Hardware LL .- 0 06> ) 
 I .4
  C Mathworks C .> != 
= 0 ! Ardent Computer
organization
." * !
/K
B   *
?? +4
#$ ) B  Mathworks C IK
#6 MC:
 /" 0 
) MIT - 0  
")
(  ( I

" .") ! 2 . *
1980 ) 
' - 0 M.S.E.E & (C .") ! B 1978

 =?
4 =?1-
Simulink&2-
Control System Using the Matlab  N  3-
Signal Application Using Matlab  N &C  =?4-
Digital Signal Processing Using Matlab  N  &C ")5-
Numerical Application Using Matlab  N = 4 6-
Image Processing Applications Using Matlab  N 
  - =?7-
Radio Frequency Applications Using Matlab  N
  
 =?8-
Mechanical Applications Using Matlab  N  =?9-
Radar Applications Using Matlab  N   =?10-
Robots Applications Using Matlab  N 

 =?11-
Electronics Applications Using Matlab  N 
 =?12-
Semiconductors Applications Using Matlab  N 
 AC =?13-
Automotive Applications Using   N  ) #$   =?14-
Matlab
Aerospace and   N 1
 E$ 
,4' 
") #$   =?15-
Defense Applications Using Matlab
Communication Applications Using Matlab  N 5 =?16-

3
‫ااد م ن ذب‬

:@ ,<   0 0


  
 + .C ! + 0 - 

 -  $
'" #) :
  7 A :  71-
.  < B
 / (
 D .") !      /@
 

# 
  #  !6 (- !- # (
!@
 0 )
  A :  !) @2-
04 4  
! workspace #$ 7
& O ( #") !C #

.LLLLLLL =?
 & 
?" !@

0 -  " #) :


  
 04 
 + !-"   :
 + !-3-
.
  =


  - 
 - 66

@ 5 !
 0 #P
" !" =" 0 -
)
  # : 4 /@
"  4-
sum , sine , cosine & complex arithmetic !LLL6

C . 4


$ 
. !6   7 + Matlab ? 5-

4
‫ااد م ن ذب‬

* ( 

.

:Command Window"- &$1-


0 : /@4
& ) &$ A $
 .C !C "-   ($
*" @ &$
:(
.- & )
 *  $
 # !
 +    & ) M
 .") E? L1
.  *@ .") E? L2
.  A7
!-  .") E? L3
.  ) BP$>
B$ & 
 7 
!- !  
 .") E? L4
Semulink...
demo !6 *" )'   Q$ L5

5
‫ااد م ن ذب‬
:Current Directory!- 2-
#$

 Work " 
* A$
 1 #@="  .B$ !- 1 # "  #$ !6
1

*  $
 # !
" !( !7> 0 0 #@="   .*  
#'  7(.m). @ B'"  Q$  1 J? ?  " 
'" $
"Enter"< .") = ) 7 !-'
&C 2  
   != < >
&
 #$ 5  - 0    2 ! - 0

: WorkSpace!- ! 3-
  !   .7 ! &  =
('-  # 7 , !   !   #$
 .5- 0 2 P
 5 - #$ &C B->
7"   = I' > & )
4 0 0 .  ) B"  #7 2 !- !  
 / &C  * J"7
  !   R$>
:Command "- /C4-()

(
(x,y,z ) !6 7 , 2 S- #-

History
 "- &$ #$  '  # = "- $ 

!   &$ A #$
. Q' 
 #$    < .") ?74 ?=$ ( /("-' & )> 
!6

6
‫ااد م ن ذب‬

: MATLAB .") < !



 P + BC 5 ( M   !
)
 /@
 1 K <( 
  ) =   
 0) &) # !

:!
 0 0)
 0 <   B .> 
 #7 B 5>
. - $ ( 5 0-  (<
M-File E
 0 /" ! 0 ' ( 
= # !
 .1

7
‫ااد م ن ذب‬
 )> J? 0) 2
B$ &

   !
 .> !
$4
 >  Q Matlab L * 0N$
.0- N ('
&$ ! 0 M-File '" !
 A
: # &) + ? !
 #$   /-  
m-files #$   ' 
.  ' B  1 B'
  /- #$

    0
 0 •
. $ B !' 5 
+?= 0 0
    0
 0 •
. / 31    <
  5 0 •
. < B)> 0
/      0 •
.&C /" CC .")

 Run  0 B"7C 0
  B  6 *    *"   )

: m-file #$ ?  '


: # *  
= 6 new m-
m-file Q'
function y = sample(x)
y=x+x.^2Ux.^4

  C ?


 & - !
#
Matlab L * #$ < !

.( 

 $-   0
&C (  
*"
: ( % 4- # !
 0
Matlab .") < !
 0 6 2
:= !

8
‫ااد م ن ذب‬
'
  

.= "- Q # DN 


= Rem

U∞ A  $
'
 1C-  = Floor

∞ A  $
'
 1C-  = Ceil
' A  1C-  =
Fix
.?=$ Q  .") !

 ,7 
= #-

Q   A  1C-  = Round


(1U2) !


:6"6 !
 

'
  

.
<   Sin
.
<"    Cos
.
< !  Tan
.
<"  !  Cot

sec( x )  Sec

csc( x )  Csc

.
<  
"- 1@   = 
<  $- Asin

.
<   
"- 1@   = 
<  $- Acos

.
< ! 
"- 1@   = 
<  $- Atan

.
< !  
"- 1@   = 
<  $- Acot

csc I
- Acsc

sec I
- Asec

sin  @<  Sinh

cos  @<  Cosh

9
‫ااد م ن ذب‬

sinh I
- Asinh

cosh I
- Acosh

(1U3) !


:
  !
 

'
  
x
e Exp

#-     Sqrt
="? =   Abs
)  2C = Gcd
7  2C /)4 Lcm
.- =   Max
:7 =   Min
.=" Q #" ="? = Mod
.=" Q #  Rem

2.7183 #-? I 


 :#-? P
"=e Log

.2 I 
 P
" log2

(10I 
)1C- I 
 P
" log10
.
4  Factorial
. "    "  )
==  ) 0   ) 0
 Complex
.#" -" J$ $- Conj
 - 0 #" ,<    Imag
 - 0 #== ,<    Real

:MATLAB .") 


: -  #66
#@6 > 

10
‫ااد م ن ذب‬
 0 B   
 !

$
'
(  S) #$ ) >
& &  Matlab * 2"

 .")  ="-  D > > .> $4 

 !C  2" 2 .> $4 -  66 !C 
*   =
.B$ &<    0 Matlab #$ $
'
4   > 0
 2
()?

:(
(=
7 
 

 
? 0
 7 !6  .")  ) !@
Matlab

'
  
. 2-D -  @6 ? "   plot
. -  #66 "   Plot3
%  !C 0
" #
 0
" + 0 meshL C
#66 "


surf
.3-D - 
%  !C 0
" #
 0
" + 0 meshc L C
"


Surfc
.3-D -  #66
.C !C .") 3-D 66 6 5 
 .") " mesh

 !
 -
A   0 !  04 @6 
 .")  
=
ezplot
.0

.3-D -  #66  #$ (  
 /- meshgrid

hold on  ("-'  8 . 0 6   "- A  =
hold
hold off  ($=  2 -
,C
.  .") 0
)  Title
. " #=$  
  Xlabel
. " 1
- 
  Ylabel
." 86 - 
  Zlabel
.(  =
)  .") C  grid on
. 
?> #$ "' 
 & ) S- subplot
.  .") J"- 1  Text
. (7 ,)  V' Legend
.!C  A > 1 0   view
.
 !
?   axis
. - 66
 0 - #$ " ?? !- contour

:  0
     0 6 
11
‫ااد م ن ذب‬

0 J< J< #


 4 '
 S  0
"

B C M G Y K W R <

:#"   ?


? E
 !
 0 < 0


UU U. : U <

Dashed Dash dot Dotted Solid ? E




12
‫ااد م ن ذب‬

? " MATLAB  


"6  < "-
25=22+3 + +  ")
36=54U90 U V? ")
2.669=0.85*3.14 * 4 ")
7=8/56 /or\ = ")
256=8^2 ^ I  ")

:"6  S-
>> 2/3^2
ans =
0.2222
>> (2/3) ^2
ans =
0.4444
>> 2+3*4-4
ans =
10
>> 2^2*3/4
ans =
3
>> 2^(2*3)/(3+4)
ans =
9.1429

13
‫ااد م ن ذب‬

( 

"- &$ #$ (  # = "-
#$ @=" "   $ R$>clear
( @
= 
 0 "- &$ /clc
!- !  #$ "  7 , (>who

$
'"  (
 )  (  !- !  #$ "  7 , (>whos
()

current directory !-  0 0pwd
!-  #$ A

 '" ,what
  0ans
3.1416 1
 # 1 0) &) pi
(5inf
inf/inf
 0/0 *@ !6 .- ( I B" 0) < &)nan

clear5 !6

14
‫ااد م ن ذب‬

 &   clear     -


B$-$ B 0)   x  $)  -
)  Q  
x,y,z 7 0 6   0   x!  B  I  B $ ,  0)
5   x 6 ?=$ 

:

clear x

 

J? A  A ?C
(x3) +' 0x) 3) !6  (= 5   (x,y,z) !6 7  )
.$
' !-  0   #$  /" '  )

* @


15
‫ااد م ن ذب‬

STAR
#$  = ! #$ @= A   A'  J? .> !

" @= A  
 &
 >  *

FIEL

16
‫ااد م ن ذب‬

EDIT

Debug

Stop If Errors/Warnings…
Stop If Errors/Warnings…

 ,? 8
 )  * / #$ 5  2?- &$ 
( 

17
‫ااد م ن ذب‬

Desktop:
Desktop:
!6  (!- 0 +? 0  '
 % -?) (@'>
 
 &$ (>  
% 6$  *  ( 
 :
 

::
0-4
  #$ $
 0

1- Docked: ( 0 2" " P &$ 0
 8..
2- Undocked: %4 (= ! -
2" " &$ 0
 8

 

18
‫ااد م ن ذب‬

@ Window:
.6  P
Command
Command Window 
 &$ !6 $
 2
'"  '" 0 != 2 8

Help
\
- C ! !@

* #$ 
4  ) $
 @= 2" 
= 8
<"  7"  "- 2
6 

19
‫ااد م ن ذب‬

‫)" ?= ‪*" @ ' #$‬‬


‫)"  ‪:+‬‬

‫; )  ‪"+"



+ " /
- <  #$ +‬‬
‫ >   ‪# !6  5

 &
 #$   +4
  
= 2+3 +‬‬
‫‪% 6$‬‬

‫‪20‬‬
‫ااد م ن ذب‬


 &$ ! " &$ 
(  
< &= I
 = 
Workspace &$ .>  >
!6  !'  #$ 
 &$ 

21
‫ااد م ن ذب‬

‫'‪# !6 #$  *@ ! - &$ JPN  3 .> 5 * 7   S‬‬

‫‪22‬‬
‫ااد م ن ذب‬

= * 
(  
 &$ #$ ans   #  (-4
 
 &$ &
) 
!6  3 #
&  

:V? ")
!6  1=2U3 
% 6$  #$ ( U ) < V? ") ;

23
‫ااد م ن ذب‬

‫)" ‪4‬‬
‫ ‪!6  180 =12*15‬‬
‫; )" ‪% 6$ ( * ) < 4‬‬

‫‪24‬‬
‫ااد م ن ذب‬
:= ")
!6  4 :
 3 .") 12  % 6$ ( / ) < = ") ;

:I  +4
")
Q' 
 #$ Shift + 6 .") ?74 ! 0 <  .") !
 0 ( ^ ) I  < ;
!6  144=2^12  % 6$
25
‫ااد م ن ذب‬

:#-   
 12 1
 144 " #-   
% 6$ sqrt,
sqrt,    J? 0)  1 #-    
# !6

  ,6 0
) +4

8 B 
=  0
) +4
$   * 0 6  P
C++
C++
Qbasic * #$ 
- 
.* 0  ,< #$ B 
=  $- #$  +  !6 0

5  - A   6 ( % ) 
@ ) +4
   0 0 5  0
) +4
  * #'$
# !6

26
‫ااد م ن ذب‬

‫‪27‬‬
‫ااد م ن ذب‬

‫‪:$
-
 * #$ % = $- 7 S-‬‬

‫‪28‬‬
‫ااد م ن ذب‬

 *  !


 S-
Trigonometric functions 6"6 !

Trigonometric
Inverse Trigonometric functions - 6"6 !

Hyperbolic Functions  @< !

Inverse Hyperbolic functions -  @< !


Trigonometric Functions6"6

29
‫ااد م ن ذب‬

Radian1@   = 


< I=  
= :
# !6 5

30
‫ااد م ن ذب‬

‫
! ‪:- 6"6‬‬

‫ ‪ 
( ,<  2" ! .")  " :  : # !6‬‬

‫'‪- 6"6 !
 ! =? I‬‬

‫‪31‬‬
‫ااد م ن ذب‬

Hyperbolic functions @< !




 @< !
"  ( - S-

32
‫ااد م ن ذب‬

-  @< !
 Inverse Hyperbolic Functions

-  @< !
" ( 0
= S-

33
‫ااد م ن ذب‬

!
 4
 5 - #$ (z
(z) 7 S
- ! 0  
=
-  @< !
 .")

Complex numbers and their Processes(")


  ) 
Natural Logarithm-? P
"
Absolute Value="? =
Approximation Processes= "-
Exponential Function   
# 4 7 ;    

exp#$ $  #$ 


# !6 

34
‫ااد م ن ذب‬

Complex Numbers  ) 
- ,<
Real number #== )^ ,< 
 #
& 
7   )  ;
# 7 #$ 0

Imaginary Numbers, #"
Imaginary Numbers,

!6   )  #$  #


"- 0  -  * #$ 

?=$ #== - >


?=$ #" - >

# - ! 0 (") !


 
Phase Angle,
Angle, 
<  >

35
‫ااد م ن ذب‬

‫>  = ?"=‪# - ! 0 (") !


 
:‬‬

‫ ‪+   )  +
(4- + ==  )  + J? 0) 2 
:0 0 ) +‬‬
‫‪(4-‬‬
‫ ‪"- 2" & C # !6‬‬

‫‪36‬‬
‫ااد م ن ذب‬

%4   )  .") ( P


V?
+ )  "- +  :
angle(z)  J? 0) 
? 
<   angle    > J !6 #$  
angle(
atan2

\   N 2 ' % 4     #$ z  - < +4
 8
atan2
# !6 

37
‫ااد م ن ذب‬

-? P
" Natural Logarithm
< -? P
"  < log(x)
log(x)
0 0 -
 ) = "-
0 0  > .") & = B $ 0 0 0 +
B; < 1C)  1
0   N Ceil  
    Floor 7   

38
‫ااد م ن ذب‬
# !6 

$
' Matrices


39
‫ااد م ن ذب‬
:$
'
( 
:Vectors (  

  ! > #$ (  




)
 
/ #$ +4
  )  0 )
  0) &)
 
.  .") !

:(  0 0)
  
 B 1
: #' B  .1
:# B - &


>> x=[3,5,2,8,11]
x=
3 5 2 8 11

. 
/  B  ) + 0 Q4
  
"' ) 0 5%  $ +4
0

:1
) B  .2

>> x=[3;5;2;8;11]
x=
3
5
2
8
11

:(   !



  "-
"- A - VC 0_ 
= /

( 
(  0 <
(  .")  '  # !
 0  - 2
: "6  ! 0 !


:!6 #$  B  ) )  


= :Length   .1
>> v=[2 5 0 1 4 -1]
40
‫ااد م ن ذب‬

v=
2 5 0 1 4 -1
>> length(v)
ans =
6

:!6 #$  B  ) + !  N   A 


= :Sum   .2

>> w=sum(v)

w=
11
:!6 #$  = 8 0 B  )   N   A 
=:Max   .3

>> w=max(v)

w=
5
:!6 #$  = 8 0 B  ) 7  N   A 
= :Min   .4

>> w=min(v)

w=
-1
$
'
   I #?- :Size   .5

>> Matrix=[1,2,3,;4,5,6]
Matrix =

1 2 3
4 5 6

>> [Matrix]=size(Matrix)
Matrix =

2 3

%  ) %  B  )    A 


=:Sort   .6

>> r=[9 7 5 8 3]

r=
9 7 5 8 3

41
‫ااد م ن ذب‬
>> s=sort(r)
s=
3 5 7 8 9
B$  7
  #$   0 J'    A 
= :Range   .7

>> range(r)

ans =
6

I .> +$
4
V?
+  ")  "- A !C
:(  .")  K >  #  "-
.$
'   .  (- + "- A 0  &C   0

:Q4
" "6  S-
>> x=[1,3,5];
>> y=[2,4,6];
>> z=x+y
z=
3 7 11
>> m=y-x
m=
1 1 1
>> p=x.*y
p=
2 12 30
>> p=x.^2
p=
1 9 25


:Matrices $
'

42
‫ااد م ن ذب‬
# !C ;
& )
/
' &
 #$ (-4
 #
 0 )
  #

' 5 - 0 )


  ! #$
Polynomials,
Polynomials,
 6 ! #$ $
'  

: * #$ $


' 
.
#6 6 !
 / )  $
' ! > 
# !6 $
'  
% 6$

 0 !' 


!
 / )   B; "- 0 +  .") # = ! > ! 0

/  ! > -   0 Space $ !-


 Comma (,) "' > !
 /
.") ?74 > (B ! >  1 ) #6 / ) 0) !
 / ) !$  !

# !6  Semicolon ( ; ), ?
= "'  N
 Enter V'

43
‫ااد م ن ذب‬

/
' 0 0
 $
'
%  A 0
  & )
B-  0-  0) &) # $
' 0 
.& )  )
n
/
' )
m 0 8 (mxn)  0 !
=  & )
& )

>> Matrix=[1,2,3,;4,5,6;7,8,9]

Matrix =

1 2 3
4 5 6
7 8 9
.$
' 0 86
 #6 /  > +? ;$ $
'   0 > 2
44
‫ااد م ن ذب‬
>> Matrix(2,:)
ans =
4 5 6

.$
' 0 86
 #6
-  > +? 2

>> Matrix(:,2)
ans =
2
5
8

& )   $
' ) +   >
>> Matrix(:)

ans =
1
4
7
2
5
8
3
6
9
:#6
-
!
 / #$ +
 -   > 
>> Matrix(1,2)

ans =
2
:$
' 0
)
 / /

>> Matrix(:,2) = [ ]
Matrix =
1 3
4 6
7 9
>> Matrix(2,:) = [ ]
Matrix =
1 2 3
7 8 9
:$
'"
)
 / /4

>> Matrix=[1,2,3,;4,5,6;7,8,9;10,11,12]
Matrix =
1 2 3
4 5 6
7 8 9
45
‫ااد م ن ذب‬
10 11 12
:$
' ? 

>> diag(Matrix)
ans =
1
5
9

:(Transpose) $
' !
= 
0 (") ! # m × n    0 $
' B; A $
'" !
= /- n × m    0 $
' A = [aij ] 0
. A T < A !
=" < #
 .") A /
' # ( )
A & ) # ($
' 0
 8 A

>> A=[1 3 5; 2 4 6]

A=

1 3 5
2 4 6

>> A'

ans =

1 2
3 4
5 6
% @= det(A ) < B <
$
'  /- n    0 - $
' A = [aij ] 0 :  
:#
det(A ) = a11 ⇐ n = 1 0 > .1
det(A ) = a11a22 − a12a21 ⇐ n = 2 0 > .2
n
det(A ) = ∑ (−1) j +1 a1 j det A1 j ⇐ n > 2 0 > .3
j =1
:  Q4
 !6
>> A=[1 0 3 ; 4 5 0; 7 8 9]

A=

1 0 3
4 5 0
7 8 9
>> det(A)

46
‫ااد م ن ذب‬
ans =
36

:#" $ (4


 /
 #  5  $
' E
 S- .> &C   

.$
'" #-   # $
' A -
' 0) &)  ) ! 0
 # #
:' $
' .1

>> x=zeros(3,2)

x=

0 0
0 0
0 0

. 
 0  ) + 0
 # $
' #
:Q 
  ) + # $
' .2

>> x=ones(3,2)

x=

1 1
1 1
1 1

.' :   ) #


Q 
 ( #@ ?= ) + 0
 - $
' #
: & 
 $
' .3
>> id=eye(4)

id =

1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1

47
‫ااد م ن ذب‬

: Matrix Algebra $


' 
!
 /

  )  .") (=?  #  -  "- #$ &
(- )
= P )
 .") $
'  -
:0  = )
= A Q4
 #" $
:$
'  !
 
:!6 #$  &  .") ! $
' & ) 0
) ! ) +  
= #
:Sum  .1
>> x=[1,2,3;4,5,6;7,8,9]

x=

1 2 3
4 5 6
7 8 9

>> A=sum(x)

A=

12 15 18

>> A=sum(x')

A=

6 15 24
:!6 #$  $
' & ) 0
) ! #$

   S- 
= #
:Max   .2
>> B=max(x)

B=

7 8 9

>> B=max(x')

B=
3 6 9
: !6 #$  $
' - S-   A 
= :Size   .3
>> [C,D]=size(x)

C=

48
‫ااد م ن ذب‬
3

D=

3
:$
' .")  "- , > 
$
' ) 0 B  - + .
 $
' ) 0 ) ! +  +  ") :+  .1
:!6 #$  6
>> A=[1,3;5,7];
>> B=[2,4;6,8];
>> C=A+B

C=

3 7
11 15

>> C=A+3

C=

4 6
8 10

) 0 B  - + .


 $
' ) 0 ) ! V? V? ")  :V? .2
:!6 #$  6 $
'
>> C=A-B

C=

-1 -1
-1 -1
:!6 #$  S- $
' ) 4 4 ")  :4 .3
>> C=A*B

C=

20 28
52 76
:!6 #$  &

 I .> - $
' +$   :(I)&
 .> $
' +$ .4
>> C=A^2

C=

16 24
40 64

49
‫ااد م ن ذب‬
‫‪>> C=A.^2‬‬

‫=‪C‬‬

‫‪1 9‬‬
‫‪25 49‬‬

‫‪50‬‬
‫ااد م ن ذب‬

!
""6
: (1)‫"!ل‬#
‫؟‬ 2
y 1 = x cos x , y 2 = x sin x , x = −2 : 0.1: 2 2
'(1+‫ ا‬2345 0.+!/+‫ ا‬-./+‫ا‬,+‫ار(' ا‬
:78+‫ا‬
>> x=-2:0.1:2;
>> y1=x.^2.*cos(x);y2=x.^2.*sin(x);
>> plot(x,y1);
>> hold on
>> plot(x,y2);
>> hold off
>> xlabel('x-axis')
>> ylabel('y-axis')
>> grid on
:9+!/+‫(' ا‬1+‫! ا‬4+ 1:;‫ی‬
4

1
y axis

-1

-2

-3
y1
y2
-4
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
x axis

y 1 = x 2 cos x , y 2 = x 2 sin x -./+‫ا‬,+‫ر(' ا‬

: (2)‫"!ل‬#
‫ ؟‬x=-4:0.1:4 , y=x^2 0+‫ا‬,+‫ار(' ا‬
:78+‫ا‬
>> x=-4:.1:4;
>> y=x.^2;
>> plot(x,y,'o')
16
:9+!/+‫(' ا‬1+‫! ا‬4+ 1:;‫ی‬
14

12

10

8
Y

0
-4 -3 -2 -1 0 1 2 3 4
X

51
‫ااد م ن ذب‬
y=x.^2 0+‫ا‬,+‫ر(' ا‬

: (3)‫"!ل‬#
2 2
‫ ؟‬z = 2xy /(x + y ), for ,x = 1: 0.1: 3, and ,y = 1: 0.1: 3 0+‫ا‬,+‫ار(' ا‬
:78+‫ا‬
>> [x,y]=meshgrid(1:0.1:3,1:0.1:3);
>> z=2*x*y/(x^2+y^2);
>> surf(x,y,z);
>> xlabel('x')
>> ylabel('y')
>> zlabel('z')

:9+!/+‫(' ا‬1+‫! ا‬4+ 1:;‫ی‬

1
z

-1

-2
3
2.5 3
2 2.5
2
1.5 1.5
y 1 1
x

z = 2xy /(x 2 + y 2 ) '(‫ر‬

>>contour(x,y,z)
>> xlabel('x')
>> ylabel('y')

52
‫ ن ذب‬ ‫م‬
figure 3.1 ‫ااد‬
3

2.8

2.6

2.4

2.2

y
1.8

1.6

1.4

1.2

1
1 1.2 1.4 1.6 1.8 2 2.2 2.4 2.6 2.8 3
x

z = 2xy /(x 2 + y 2 ) 0+‫ا‬,+‫?>= ا‬#

:(4)‫"!ل‬#
‫('؟‬1+‫ ا‬23‫ ﻥ‬9J !@:GE5 H# -./+‫ا‬,+‫ح وا‬1>+‫ ا‬7B!‫@! وﺡ‬:E@F 7B!‫ وﺡ‬cosn(x),sin(x ) 0+‫ا‬,+‫ ا‬9@(‫ار‬
:78+‫ا‬
x=-10:.01:10;
y1=sin(x);
subplot(3,2,1)
plot(x,y1);xlabel('x');ylabel('y');title('sin(x)')
subplot(3,2,2)
y2=cos(x);
plot(x,y2,'r');xlabel('x');ylabel('y');title('cos(x)')
subplot(3,2,3)
plot(x,y1+y2,'k');xlabel('x');ylabel('y');title('sin(x)+cos(x)')
y4=y2-y1;
subplot(3,2,4)
plot(x,y1,x,y4);xlabel('x');ylabel('y');title('cos(x)-sin(x)')
y5=sin(x);
y6=cos(x);
subplot(3,2,5)

53
‫ااد م ن ذب‬
plot(x,y5,'r',x,y6,'k');xlabel('x');ylabel('y');title('sin(x) and cos(x)')
sin(x) cos(x)
1 1

0 0

y
-1 -1
-10 -5 0 5 10 -10 -5 0 5 10
x x
sin(x)+cos(x) cos(x)-sin(x)
2 2

0 0

y
-2 -2
-10 -5 0 5 10 -10 -5 0 5 10
x x
sin(x) and cos(x)
1

0
y

-1
-10 -5 0 5 10
x

cosn(x),sin(x ) -./+‫ا‬,K+ '(‫ر‬

:(5) ‫"!ل‬#
sin(R )
‫ ؟‬Z = ‫ و‬R = x 2 + y 2 0+‫ا‬,+‫ ا‬9@(‫ار‬
R
:78+‫ا‬
>> [X,Y] = meshgrid(-8:.5:8);
>> R = sqrt(X.^2 + Y.^2);
>> Z = sin(R)./R;
>> surf(X,Y,Z)

0.5
Z

-0.5
10
5 10
0 5
0
-5 -5
y -10 -10
x

54
‫ااد م ن ذب‬

$
' 
:(6) ‫"!ل‬#
c=repmat(5,4,6)

c=

5 5 5 5 5 5
5 5 5 5 5 5
5 5 5 5 5 5
5 5 5 5 5 5

A=[1 2 3 4 5]
Sum(a)
sum(a)
ans =
15

(  V?


:(7) ‫"!ل‬#
d=[2 4 8 10 12]

d=

2 4 8 10 12

>> e=[1 3 7 11 13]

e=

1 3 7 11 13

>> f=d-e

f=

1 1 1 -1 -1

55
‫ااد م ن ذب‬

arc tan, arc cos , arc sin


:(8) ‫"!ل‬#

y=1:0.1:10;
>> plot(y);

>> x=0:0.1:10;
>> y=san(x);
>> y=sin(x);
>> plot(x,y);

>> x=0:0.1:10;
>> y=sin(x);
>> z=cos(x);
>> w=[y;z];
>> plot[y;w];
plot(x,w);

:(9) ‫"!ل‬#

fplot('sin(x)',[-pi,pi])
>> fplot('sin(x^2)',[-pi,pi])

56
‫ااد م ن ذب‬

mesh

:(10) ‫"!ل‬#
>> mesh(peaks);
>> [x y z ]= peaks(100);
>> figure;
>> mesh(x,y,z);

[x y z]=peaks(40);
meshc(x,y,z);

   SURF

:(11) ‫"!ل‬#
x,y,z]=peaks(30);
>> surf(x,y,z);
>> xlabel('x-axis','fontsize',11);
>> xlabel('y-axis','fontsize',11);
>> xlabel('z-axis','fontsize',11);
title('ISSAM SERHAN DYAB');

57
‫ااد م ن ذب‬

:(12) ‫"!ل‬#

x=linspace(0,10,100);
>> y=cos(x);
>> [x y]=meshgrid(x,y);
>> z=sin(x).*exp(-0.3.*x)./(cos(y)+2);
>> mesh(x,y,z);

:(13) ‫"!ل‬#

>> x=linspace(0,10,1000);
>> y=cos(x);
>> [x y]=meshgrid(x,y);
>> z=sin(x).*exp(-0.3.*x)./(cos(y)+2);
>> mesh(x,y,z);

58
‫ااد م ن ذب‬

Fplot
:(14) ‫"!ل‬#

fplot('sin(x)',[-pi,pi])
>> fplot('sin(x^2)',[-pi,pi])

:(15) ‫"!ل‬#

fplot('sin(x)*cos(x)',[-pi,pi])
>> grid on
>> help grid
GRID Grid lines.
GRID ON adds major grid lines to the current axes.
GRID OFF removes major and minor grid lines from the current axes.
GRID MINOR toggles the minor grid lines of the current axes.
GRID, by itself, toggles the major grid lines of the current axes.
GRID(AX,...) uses axes AX instead of the current axes.

GRID sets the XGrid, YGrid, and ZGrid properties of


the current axes.

set(AX,'XMinorGrid','on') turns on the minor grid.

59
‫ااد م ن ذب‬
See also title, xlabel, ylabel, zlabel, axes, plot, box.

Reference page in Help browser


doc grid

:(16) ‫"!ل‬#

clc
>> x=[1 2 3 4 5 6 7 8 9 10]
x=
1 2 3 4 5 6 7 8 9 10
y=[2:2:120]
y=
Columns 1 through 14
2 4 6 8 10 12 14 16 18 20 22 24 26 28
Columns 15 through 28
30 32 34 36 38 40 42 44 46 48 50 52 54 56
Columns 29 through 42
58 60 62 64 66 68 70 72 74 76 78 80 82 84
Columns 43 through 56
86 88 90 92 94 96 98 100 102 104 106 108 110 112
Columns 57 through 60
114 116 118 120

length(y)
ans =
60
Plot(y)

60
‫ااد م ن ذب‬

‫ره‬efg‫ و‬h‫و‬ijk‫ا‬
:(17) ‫"!ل‬#

title('dyaila university')
xlabel('ISSAM SERHAN')
>> ylabel('sin(x)cos(x)')
>>

61
‫ااد م ن ذب‬

Issam serhan dyaib


dyaib

62
‫ااد م ن ذب‬

(1) h lm
x = linspace ( 0, 10*pi, 100 );
y = exp ( -0.1 * x ) .* sin ( x )
plot ( x, y )
hold on
plot ( x, exp ( -0.1 * x ) )
plot ( x, -exp ( -0.1 * x ) )
hold off

63
‫ااد م ن ذب‬

(2) h lm
x = 2 * pi * rand ( 10, 1 );
x = sort ( x );
y = sin ( x );

xx = linspace ( 0, 2*pi, 100 );


yy = spline ( x, y, xx );

plot ( x, y, '*', xx, yy, 'r' )

64
‫ااد م ن ذب‬

(3 )h lm

x = linspace ( -2, 2, 10 );
y = x.^3 - x.^2 - 2*x;

xx = x;
yy = y .* ( 1.0 + 0.5 * randn ( 1, 10 ) );
plot ( x, y, 'b*-', xx, yy, 'ro-' )

65
‫ااد م ن ذب‬

(4) h lm

x = 0 : 0.1 : 2;
taylor = x - x.^3 / 6;
error = taylor - sin ( x );
errorbar ( x, taylor, error )

66
‫ااد م ن ذب‬

(5) h lm

X = F(T)
Y = G(T)
-------------------------------:
t = 0 : 0.1 : 2*pi;
x = t .* sin ( 3 * t );
y = t .* sin ( t ) .* sin ( t );
plot ( x, y )

67
‫ااد م ن ذب‬

(6) h lm

x = linspace ( 0, 2*pi, 100 );


subplot ( 2, 2, 1 ), plot ( x, sin(x) )
subplot ( 2, 2, 2 ), plot ( x, sin(2*x) )
subplot ( 2, 2, 3 ), plot ( x, sin(x+2) )
subplot ( 2, 2, 4 ), plot ( x, sin(x).^2 )

68
‫ااد م ن ذب‬

(7) h lm

theta = 0 : 0.1 : 8 * pi;


r = theta + 1;
x = r .* cos ( theta );
y = r .* sin ( theta );
plot ( x, y )

theta = 0 : 0.1 : 8 * pi;


r = theta + 1;
polar ( theta, r )

69
‫ااد م ن ذب‬

(8) h lm

y = rand ( 1000, 1 );
y = fix ( 20 * y );
hist ( y, 20 )

y = randn ( 1000, 1 );
hist ( y, 20 )

70
‫ااد م ن ذب‬

(9) h lm

Continents = [ 88, 33, 22, 33, 7 ]


pie ( Continents )

71
‫ااد م ن ذب‬

(10) h lm

axis ( [ 0, 1, 0, 1 ] )

x1 = [ 0.0, 0.5, 0.5 ];


y1 = [ 0.5, 0.5, 1.0 ];
fill ( x1, y1, 'r' )

hold on

x2 = [ 0.75, 1.0, 0.75, 0.5 ];


y2 = [ 0.0, 0.25, 1.0, 0.25];
c2 = [ 0, 0, 1 ];
fill ( x2, y2, c2 )

72
‫ااد م ن ذب‬

(11) h lm

x = randn ( 20, 1 );
y = randn ( 20, 1 );
scatter ( x, y )

73
‫ااد م ن ذب‬

(12) h lm

x = [ 1.0, 2.0, 2.0, 3.0, 3.0, 2.0, 2.0, 1.0, 1.0, 0.0, 0.0, 1.0];
y = [ 0.0, 0.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 2.0, 2.0, 1.0, 1.0];
fill ( x, y, 'r' )

74
‫ااد م ن ذب‬

(13) h lm

x = randn ( 20, 1 );
y = randn ( 20, 1 );
scatter ( x, y )

hold on
k = convhull ( x, y );
plot ( x(k), y(k) )

75
‫ااد م ن ذب‬

(14) h lm

x = randn ( 20, 1 );
y = randn ( 20, 1 );
tri = delaunay ( x, y );
[ ntri, ncol ] = size ( tri );
tri(:,4) = tri(:,1);
scatter ( x, y )
for i = 1 : ntri
line ( x(tri(i,:)), y(tri(i,:)) )
end

76
‫ااد م ن ذب‬

(15) h lm

x = randn ( 20, 1 );
y = randn ( 20, 1 );
voronoi ( x, y )

77
‫ااد م ن ذب‬

(16) h lm

[x,y] = meshgrid ( 0:0.2:2, 0:0.2:2 );


u = cos(x) .* sin(y);
v = sin(x) .* y - log(x+1);
quiver ( x, y, u, v )

78
‫ااد م ن ذب‬

(17) h lm

x = 2 * rand ( 121, 1 );
y = 2 * rand ( 121, 1 );
u = cos(x) .* sin(y);
v = sin(x) .* y - log(x+1);
norm = sqrt ( u.*u + v.*v );
indx = find ( norm );
u(indx) = u(indx) ./ norm(indx);
v(indx) = v(indx) ./ norm(indx);
quiver ( x, y, u, v )

79
‫ااد م ن ذب‬

(18) h lm

[x,y] = meshgrid ( 0:0.2:2, 0:0.2:2 );


u = cos(x) .* sin(y);
v = sin(x) .* y - log(x+1);
startx = [0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2];
starty = [1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9]/5;
streamline ( x, y, u, v, startx, starty );

80
‫ااد م ن ذب‬

(19) h lm
load ( 'nodes6.txt' );
load ( 'velocity6.txt' );
x = nodes6(:,1);
y = nodes6(:,2);
u = velocity6(:,1);
v = velocity6(:,2);
xtab = reshape ( x, 5, 13 );
ytab = reshape ( y, 5, 13 );
utab = reshape ( u, 5, 13 );
vtab = reshape ( v, 5, 13 );
xstart = [ 0, 0, 0, 0, 0, 0 ];
ystart = [ 0, 0.2, 0.4, 0.6, 0.8, 1.0];
axis equal
streamline ( xtab, ytab, utab, vtab, startx, starty );
hold on;
k = convhull ( x, y );
plot ( x(k), y(k), 'r' );
hold off

81
‫ااد م ن ذب‬

(20) h lm

[x,y] = meshgrid ( -5:0.2:5, -5:0.2:5 );


z = 9 * x.^2 + 16 * y.^2 - 144;
contour ( x, y, z );
axis square
axis equal

82
‫ااد م ن ذب‬

(21) h lm

[x,y] = meshgrid ( -5:0.2:5, -5:0.2:5 );


z = 9 * x.^2 + 16 * y.^2 - 144;
surf ( x, y, z )

83
‫ااد م ن ذب‬

(22) h lm

(‫ ك‬op‫ج و‬elp‫ ﻡ‬v‫ﻥ‬wt xy ‫ ك )أي‬op‫ ﻡ‬r‫ ﻥﻡ‬t

nframes = 51;

x = linspace ( -12.0, +12.0, 51 );

for i = 1 : nframes
t = 2 * ( i - 1 ) * pi / ( nframes - 1 );
y = 5.0 * cos ( 2.0 * x / 12.0 ) .* sin ( t ) .* cos ( t + x );
plot ( x, y )
axis equal
my_frames(:,i) = getframe;
end

movie ( my_frames, 2 )

84
‫ااد م ن ذب‬

(23) h lm

x = linspace ( 0, 2*pi, 100 );


y = sin(x);
id = plot ( x, y );
set ( id, 'Marker', 'o' )
set ( id, 'MarkerSize', 15 )
set ( id, 'Color', 'Cyan' )

85
‫ااد م ن ذب‬

Title Author Publisher Copyright


What Every Engineer Should Biran / CRC Press, 2011
Know About MATLAB and Breiner Inc.
Simulink
The Elements of MATLAB Style Johnson Cambridge 2011
University
Press
Numerical Methods for Gilat / John Wiley & 2011
Engineers and Scientists: An Subramaniam Sons, Inc.
Introduction with Applications
Using MATLAB, 2e
Modeling and Simulation using Jain Wiley-India 2011
MATLAB-Simulink
MATLAB: An Introduction with Gilat John Wiley & 2011
Applications, 4e Sons, Inc.
MATLAB Primer, 8e Davis Chapman & 2011
Hall/CRC
Introduction to MATLAB, 2e Etter Prentice Hall 2011
The Essential MATLAB & Okoro / Juta and 2010
Simulink for Engineers and Chikuni Company Ltd
Scientists
Getting Started with MATLAB: Pratap Oxford 2010
A Quick Introduction for University
Scientists and Engineers Press
Essential MATLAB for Hahn / Academic 2010
Engineers and Scientists, 4e Valentine Press
Practical MATLAB Kalechman CRC Press, 2009
Applications for Engineers Inc.
MATLAB: A Practical Attaway Elsevier 2009
Introduction to Programming Science
and Problem Solving
MATLAB for Engineers, 2e Moore Prentice Hall 2009
Learning MATLAB Driscoll SIAM 2009
Introduction to Engineering: Brockman John Wiley & 2009
Modeling and Problem Solving Sons, Inc.
Introduction to C++, Excel, and Stenger / Pearson 2009
MATLAB & Basic Engineering Smith Education Inc
Numerical Methods V 1.1

86
‫ااد م ن ذب‬

‫‪87‬‬

You might also like