68
ن ع دمة ق مMATLAB MATLAB و أ( matrix laboratory ) و ه ج م ا رن ب ي س د ن ه دم ق ت م وم ق ي رأء ج( ا) ن ات ن ل م ع ل أ ة ي) ب سا ح ل أ حاكاة م و مة; ظ ن لأ أ ة ف ل ت ح م ل أ أ لد دم ح ت س ي لة ن س و ك ل ن ل ح ت ي ف عدة الأت ح م لQ ن م وم ل ع ل أ و ات ن ض ا رن ل أ دمة ق ت م ل أ و ي ف اعة ن ص ل أ دأة كاQ ث ح ت م ي م ص ن و أت د ردود م. ي ل عا ل م ع ت س ي ج م ا رن لب أ رأض غ لأ لk: ة ي ل ا ن ل أ رأء جn أ ات ن ل م ع ل أ ة ي) ب سا ح ل أ دة ق ع م ل أ رعة س يk. ة ف ي ا فMath and computation اق ق تQ س أ مات ت ب ار وع ل ل أAlgorithm development حاكاة م م ي م ص ن و مة; ظ ن لأ أ ة ف ل ت ح م ل أ ي ف ع ت م ج روع ف وم ل ع ل أ و اعة ن ص ل أModeling & simulation System ل ن ل ح ت ات ان ن) ب ل أ و ها ف اQ س ك ن س أData analysis and exploration م س ر مات س ح م ل أ ة ي س د ن ه ل أ و ة ي ع ا ن ص ل أ أت د k ةQ لأثQ ن ل أ عاد ي أ( Three dimension (3D ر ب ت ع يMATLAB ن م أل ج م رأ ب أت د ة اث ح ت سلأ أ عة ي ر س ل أQ ث ي ح ر ص ن ع ات ان ن) ب ل أ ي س سا لأ أ ة ي ف ارة ن ع ن ع k ة وف ق ص م دون ن عاد ي أ ة ي س ا ن ف ك ل . لد ن ك م ي دأمة ح ت س أ ي ف

MATLAB ALL Commands

  • Upload
    adnan

  • View
    972

  • Download
    4

Embed Size (px)

DESCRIPTION

MATLAB, most of matlab orders, functions, in detailsorganized in special groups for easy access

Citation preview

Page 1: MATLAB ALL Commands

عن MATLAB مقدمةMATLABأو (matrix laboratory )يقوم متقدم هندسي برنامج هو

يستخدم لذا المختلفة األنظمة ومحاكاة الحسابية العمليات بإجراء و المتقدمة الرياضيات و العلوم مثل مجاالت عدة في تحليل كوسيلة

يستعملعالي. مردود ذات وتصميم بحث كأداة الصناعة فيالتالية: لألغراض البرنامج

فائقة. بسرعة المعقدة الحسابية العمليات إجراء Math and computation

اللوغاريتمات اشتقاق Algorithm developmentالصناعة و العلوم فروع جميع في المختلفة األنظمة وتصميم محاكاة

Modeling & simulation System

استكشافها و البيانات تحليل Data analysis and exploration

الثالثة ذات الصناعية و الهندسية المجسمات رسم Three dimension (3D) أبعاد

حيث السريعة االستجابة ذات برامجال منMATLAB يعتبر أبعاد بدون مصفوفة عن عبارة فيه األساسي البيانات عنصر

المسائل معظم حل في استخدامه يمكن . لذلك قياسية باستخدام مقارنةQ قصير زمن وفي بسهولة المعقدة الحسابية

. FORTRAN أو C مثل األخرى البرمجة لغات MATLAB مكونات

: هي و رئيسية أجزاء خمسة من MATLAB برامج يتكونMATLAB language البرمجة لغة.1

فرعية ملفات من ومكونة جاهزة برمجة لغة عن عبارة وهي . الجبرية الدوال و المحددات و المصفوفات فيها تستخدم

working environment العمل محيط.2 لتمكين تستخدم تسهيالت و وسائل مجموعة عن عبارة

وسائل على المحيط هذا . يحتوي العمل من المستخدم إرسال و بجلب يقوم كما المتغيرات إدارة و لتنظيم

. المعلومات: graphics Handle البيانية الرسوم منظم.3

Page 2: MATLAB ALL Commands

أوامر على يحتوي تجسيمي رسم منظومة عن عبارة وهو يحتوي أبعاد. كما الثالثة و البعدين ذات المجسمات لرسم. وتحريكها المجسمات إلظهار أوامر على

الرياضية للدوالMATLAB مكتبة.4: التالية الدوال علي تحتوي

Fast Fourier transforms , matrix eigenvalues , matrix inverse , cosine , sine , sum

5.Application program interface

المعدة البرامج بربط تسمح مساعدة وسائل عن عبارة .MATLAB مع C) و(Fortran مثل أخرى بلغات

Toolboxes MATLAB المساعدة MATLAB وسائط للتطبيقات مساعدة وسائل على(MATLAB) يحتوي

القيام على تساعد التي(Toolboxes) تسمى و المتخصصةaالتكنولوجيا استخدام و الصناعة مجاالت في أوسع بدراسة

. المتخصصة مجموعات عن عبارة هي(Toolboxes) المساعدة الوسائل هذه

التي(M-Files) ب تعرفMATLAB)مشتقات( دوال من شاملة طابع ذات معقدة مسائل لحل كبيرة قدراتMATLAB تعطي. خاص مع ضمنيا تستخدمToolboxes مساعدة وسائل عدة هناك

MATLABمنها :SIMULINK TOOLBOX [2] CONTROL SYSTEM TOOLBOX[1]SIGNAL PROCESSING TOOLBOX [4] COMMUNICATION TOOLBOX [3]MODEL PREDICTIVE CONTROL TOOLBOX[5]

: MATLAB لي المساعدة الوسائط لبعض توضيحCommunication Toolbox

محاكاة و تحليل و لتصميم تستخدم مدمجة وسائل عن عبارة من العديد في مفيدة وهي المختلفة االتصاالت أنظمة

الالسلكية و السلكية االتصاالت مثل االتصاالت أبحاث مجاالتالصناعية األقمار و الفضائية و الرقمية االتصاالت وكذلك

Control system Toolbox مثل اآللي التحكم أنظمة محاكاة و تصميم في تستخدم الفضائية المراكب في التحكم و النفطية العمليات في التحكم

Page 3: MATLAB ALL Commands

األجهزة من العديد و الكبرى المصانع في التحكم غرف و. األتوماتيكية الكهربائية كالغساالت المتداولة

Model predictive control Toolbox و المداخل ذات اآللي التحكم أنظمة تطبيقات في يستخدم و الكيميائية الهندسة في الحال هو كما المتعددة المخارجالعمليات في التحكم

SIMULINK TOOLBOX عن مقدمةSIMULINK لل مصاحب برنامج هوMATLAB فائقة استجابة ذو

[ خطية والغير ] الخطية الديناميكية األنظمة محاكاة و لتحليل.

الهندسية الحاسوب برامج اكثر منSIMULINK برنامج يعتبرQ Q و شيوعا الصناعية و األكاديمية األبحاث مجاالت في استخداما

. محاكاتها و تحليلها و الديناميكية لألنظمة تقليدية نماذج لبناء لألنظمة نماذج بناء البرنامج هذا باستخدام للباحث يمكن

األنظمة هذه متغيرات تعديل يمكن كما محاكاتها و الحقيقية المنظومة على تحدث التي التغيرات مالحظة و المحاكاة أثناء

. باستخدام النماذج بناء عملية تتم البرنامج هذا في

البرامج عكس على فيه المخزنة الصندوقية المخططات برامج كتابة في الباحث ووقت جهد تستهلك التي و األخرى . [Fortran أو C ] مثل معقدة و طويلة SIMULINK في مخزنة الصندوقية المخططات من العديد هناك

( .1) رقم الجدول في موضح هو اكم لالستعمال جاهزة ذلك و المحاكاة عملية تبدأ للمنظومة نموذج بناء اكتمال عند

يحتوي SIMULINK فبرنامج المناسبة التكامل طريقة باختيار يمكن . و(Integration) التكامل عملية إلنجاز طرق عدة على

و منحنيات هيئة على المحاكاة عملية أثناء النتائج مشاهدةQ الموجود اإلشارات راسم باستخدام ذلك برنامج في أصال

SIMULINK .

Simulink Block LibraryCopyright (c) 1990-97 by The MathWorks, Inc.

Sources Sinks NonlinearLinearDiscrete

Demos

In Out

Connections

Blocksets & Toolboxes

Page 4: MATLAB ALL Commands
Page 5: MATLAB ALL Commands

MATLAB استخدامStarting & Ending MATLAB وإنهائه البرنامج بدء(1

من للخروجMATLAB أيقونة علي انقر البرنامج استخدام لبدءالملفات. قائمة في Exit أيقونة علي انقر البرنامج

The Command Window األوامر نافذة استخدام(2 يتم خاللها من التي الرئيسية النافذة هي األوامر نافذة

العمليات جميع فيها وتجرىInterpreter بالمترجم االتصال جاهز ىعل ليلد ك)<<( العالمة المترجم . يظهر الحسابية

. األوامر لتقبل يته Command Line Editing األوامر اسطر كتابة(3

اليسار إلي تحركواحد كلمة

Move left one wordctrl السطر استدعاء السابق

Recall previous line.

بداية إلي تحرك السطر

Move to beginning of linehomeالسطر استدعاء السابق قبل

Recall next line

نهاية إلي تحرك السطر

Move to end of lineendالخلف إلي تحرك واحد حرف

Move back one character.

األمام إلي تحركclear lineescالسطر لحذفواحد حرف

Move forward one character.

عند حرف لحذفالمشيرة

delete character at cursordelاليمين إلي تحرك واحد كلمة

Move right one wordctrl

Interrupting a Running Program البرنامج مقاطعة(4Ctrl-c ىعل بالضغط لحظة أي في البرنامج مقاطعة يمكن

Suppressing Output النتيجة تفويت(5 تظهرEnter ىعل والضغط تحليلها المراد البيانات إدخال عند

Q النتيجة بشارحة السطر أنهيت إذا الشاشة. أما ىعل فورا إظهار بدون البيانات بتحليل يقومMATLAB فان منقوطة البيانات إدخال عند مفيدة العملية . هذه الشاشة ىعل النتيجة

الكبيرة. النتيجة ذاتLong Command Lines الطويلة األوامر كتابة(6

يمكن سطر من اكثر تأخذ بحيث طويلة المعلومة كانت إذا إلي المعلومة استمرارية لبيانEnter و … نقاط ثالثة استخدام

. المقبل السطر

ENTERING MATRICES المصفوفات إدخال(7

Page 6: MATLAB ALL Commands

بواسطة المصفوفة في الواحد الصف عناصر فصل يجب كل نهاية عند منقوطة فاصلة استخدام يجب فراغات. كما قوسين بواسطة المصفوفة عناصر جميع يحاط صف. وأخيرا

] [ كالتالي: مربعينA = [16 3 2 13; 5 10 11 8; 9 6 7 12; 4 15 14 1]ىعل وبالضغط

Enter المفتاح

التالي: النحو ىعل المصفوفة بإظهارMATLAB يقوم عندهاA=

16 3 2 135 10 11 89 6 7 124 15 14 1

,sum المصفوفة وقلب جمع عملية أجراء(8transpose, and diag

sum (A)التالية: بالعملية نقوم المصفوفة أعمدة لجمع

'A المصفوفة هذه مقلوب أوال نأخذ المصفوفة صفوف لجمع كما الناتج نقلب وأخيرا المصفوفة مقلوب أعمدة نجمع ثم

يلي:sum(A')'

التالية: بالعملية نقوم للمصفوفة القطرية العناصر لجمعsum(diag(A))

mathematical expressions الرياضية التعبيرات(9 وهي: رياضيةكثيرة تعبيرات عليMATLAB يحتوي

الرموز او والمعامالتNumbers األعداد Variables المتغيراتOperatorsوالدوال Functions

O متغيرMATLAB يكتشف عندما Variables المتغيرات اوًالكتبت إذا المثال سبيل ىعل أتوماتيكيا بتخزينه يقوم جديد

num_students = 25

Page 7: MATLAB ALL Commands

. وإلظهاره أتوماتيكيا المتغير هذا بتخزين يقومMATLAB فان .num المتغير اسم فقط يكتب أخرى مرة

O األعدادMATLAB يتقبل Numbers األعداد ثانيا طبيعي بشكل

O Operators الحسابية الرموز ثالثا Addition+ الجمعSubtraction – الطرح

Multiplication* الضربDivision/ القسمة

Left division\ اليسارية القسمة

Power^ االس

Complex conjugate transpose' المقلوب

) (Specify evaluation order

O Functions الرياضية الدوال رابعاgraph2d (two-dimensional graphs) .graph3d (three-dimensional graphs) .specgraph (specialized graphs) .

graphics (handle graphics) .uitools (graphical user interface tools).

MATRIX MANIPULATION الصفوفات معالجةElementary matrices .

zeros - Zeros array. ones - Ones array.

eye - Identity matrix. repmat - Replicate and tile array.

rand - Uniformly distributed random numbers.

randn - Normally distributed random numbers. linspace - Linearly spaced vector.

logspace - Logarithmically spaced vector. meshgrid - X and Y arrays for 3-D plots.

: -Regularly spaced vector and index into matrix.

Page 8: MATLAB ALL Commands

Basic array information . size - Size of matrix.

length - Length of vector.ndims - Number of dimensions.disp - Display matrix or text. isempty - True for empty matrix.

isequal - True if arrays are identical. isnumeric - True for numeric arrays.

islogical - True for logical array. logical - Convert numeric values to logical.

Matrix manipulation . reshape - Change size.

diag - Diagonal matrices and diagonals of matrix. tril - Extract lower triangular part. triu - Extract upper triangular part.

fliplr - Flip matrix in left/right direction. flipud - Flip matrix in up/down direction.

flipdim - Flip matrix along specified dimension. rot90 - Rotate matrix 90 degrees.

find - Find indices of nonzero elements. end - Last index.

sub2ind - Linear index from multiple subscripts. ind2sub - Multiple subscripts from linear index.

Special variables and constants. ans - Most recent answer.

eps - Floating point relative accuracy. realmax - Largest positive floating point number.

realmin - Smallest positive floating point number.

pi - 3.1415926535897.... i, j - Imaginary unit.

inf - Infinity. NaN - Not-a-Number.

isnan - True for Not-a-Number. isinf - True for infinite elements.

isfinite - True for finite elements. flops - Floating point operation count.

why - Succinct answer.

Specialized matrices . compan - Companion matrix.

gallery - Higham test matrices. hadamard - Hadamard matrix.

hankel - Hankel matrix. hilb - Hilbert matrix.

invhilb - Inverse Hilbert matrix.

magic - Magic square. pascal - Pascal matrix.

rosser -Classic symmetric eigenvalue test problem. toeplitz - Toeplitz matrix.

vander - Vandermonde matrix. wilkinson - Wilkinson's eigenvalue test matrix.

ELEMENTARY MATH FUNCTIONS.Trigonometric .

sin - Sine. sinh - Hyperbolic sine.

asin - Inverse sine. asinh - Inverse hyperbolic sine.

cos - Cosine. cosh - Hyperbolic cosine.

acos - Inverse cosine. acosh - Inverse hyperbolic cosine.

tan - Tangent. tanh - Hyperbolic tangent.

atan - Inverse tangent. atan2 - Four quadrant inverse tangent.

atanh - Inverse hyperbolic tangent.

sec - Secant. sech - Hyperbolic secant.

asec - Inverse secant. asech - Inverse hyperbolic secant.

csc - Cosecant. csch - Hyperbolic cosecant.

acsc - Inverse cosecant. acsch - Inverse hyperbolic cosecant.

cot - Cotangent. coth - Hyperbolic cotangent.

acot - Inverse cotangent. acoth - Inverse hyperbolic cotangent.

Exponential . exp - Exponential.

log - Natural logarithm. log10 - Common (base 10) logarithm.

log2 -Base 2 logarithm and dissect floating point number.

pow2 -Base 2 power and scale floating point number. sqrt - Square root.

nextpow2 - Next higher power of 2.

Complex . abs - Absolute value.

angle - Phase angle. conj - Complex conjugate.

imag - Complex imaginary part. real - Complex real part.

unwrap - Unwrap phase angle.

Page 9: MATLAB ALL Commands

isreal - True for real array. Cplxpair -Sort numbers into complex conjugate pairs.

Rounding and remainder . fix - Round towards zero.

floor - Round towards minus infinity.

ceil - Round towards plus infinity. round - Round towards nearest integer.

mod - Modulus (signed remainder after division). rem - Remainder after division.

sign - Signum.

SPECIALIZED MATH FUNCTIONS. airy - Airy functions.

besselj - Bessel function of the first kind. bessely - Bessel function of the second kind .

Besselh -Bessel functions of the third kind (Hankel function). besseli - Modified Bessel function of the first kind.

besselk -Modified Bessel function of the second kind. beta - Beta function.

betainc - Incomplete beta function. betaln - Logarithm of beta function.

ellipj - Jacobi elliptic functions. ellipke - Complete elliptic integral.

erf - Error function. erfc - Complementary error function.

erfcx - Scaled complementary error function. erfinv - Inverse error function.

expint - Exponential integral function. gamma - Gamma function.

gammainc - Incomplete gamma function. gammaln - Logarithm of gamma function. legendre - Associated Legendre function.

cross - Vector cross product.

Number theoretic functions .

factor - Prime factors. isprime - True for prime numbers.

primes - Generate list of prime numbers. gcd - Greatest common divisor.

lcm - Least common multiple.

rat - Rational approximation. rats - Rational output.

perms - All possible permutations. nchoosek -All combinations of N elements taken K at a

time.

Coordinate transforms . cart2sph -Transform Cartesian to spherical coordinates.

cart2pol - Transform Cartesian to polar coordinates. pol2cart - Transform polar to Cartesian coordinates.

sph2cart -Transform spherical to Cartesian coordinates.

hsv2rgb -Convert hue-saturation-value colors to red-green-blue.

rgb2hsv - Convert red-green-blue colors to hue-saturation-value.

MATRIX FUNCTIONS - NUMERICAL LINEAR ALGEBRA.Matrix analysis . norm - Matrix or vector norm.normest - Estimate the matrix 2-norm.rank - Matrix rank.det - Determinant.

trace - Sum of diagonal elements. null - Null space.

orth - Orthogonalization. rref - Reduced row echelon form.

subspace - Angle between two subspaces

. Linear equations .

\and / - Linear equation solution; use "help slash." inv - Matrix inverse.

COND - CONDITION NUMBER WITH RESPECT TO INVERSION.

condest - 1-norm condition number estimate. chol - Cholesky factorization.

cholinc - Incomplete Cholesky factorization. lu - LU factorization.

luinc - Incomplete LU factorization. qr - Orthogonal-triangular decomposition.

nnls - Non-negative least-squares. pinv - Pseudoinverse.

lscov - Least squares with known covariance.

Matrix functions . expm - Matrix exponential.

logm - Matrix logarithm. sqrtm - Matrix square root.

funm - Evaluate general matrix function.Factorization utilities

qrdelete - Delete column from QR factorization. qrinsert - Insert column in QR factorization.

RSF2CSF -REAL BLOCK DIAGONAL FORM TO COMPLEX DIAGONAL FORM.

cdf2rdf -Complex diagonal form to real block diagonal form.

balance -Diagonal scaling to improve eigenvalue accuracy. planerot - Given's plane rotation.

Page 10: MATLAB ALL Commands

Polynomials . roots - Find polynomial roots.

poly - Convert roots to polynomial. polyval - Evaluate polynomial.

POLYVALM - EVALUATE POLYNOMIAL WITH MATRIX ARGUMENT.

residue - Partial-fraction expansion (residues). polyfit - Fit polynomial to data.

polyder - Differentiate polynomial. conv - Multiply polynomials.

deconv - Divide polynomials.

Plotting . ezplot - Easy to use function plotter. fplot - Plot function.

Ordinary differential equation solvers . (If unsure about stiffness, try ODE45 first, then ODE15S).

ode45 - Solve non-stiff differential equations, medium order method. ode23 - Solve non-stiff differential equations, low order method.

ode113 - Solve non-stiff differential equations, variable order method. ode15s - Solve stiff differential equations, variable order method.

ode23s - Solve stiff differential equations, low order method. odefile - ODE file syntax.

TWO DIMENSIONAL GRAPHS.Elementary X-Y graphs .

plot - Linear plot. loglog - Log-log scale plot. semilogx - Semi-log scale plot. semilogy - Semi-log scale plot.

polar - Polar coordinate plot. PLOTYY - GRAPHS WITH Y TICK LABELS

ON THE LEFT AND RIGHT.

Axis control . axis - Control axis scaling and appearance.

zoom - Zoom in and out on a 2-D plot. grid - Grid lines.

box - Axis box. hold - Hold current graph.

axes - Create axes in arbitrary positions. subplot - Create axes in tiled positions.

Graph annotation . legend - Graph legend.

title - Graph title. xlabel - X-axis label.

ylabel - Y-axis label . text - Text annotation.

gtext - Place text with mouse.

Page 11: MATLAB ALL Commands

Hardcopy and printing . print - Print graph or SIMULINK system; or save graph to M-file.

printopt - Printer defaults. orient - Set paper orientation .

Three dimensional graphs.Elementary 3-D plots .

plot3 - Plot lines and points in 3-D space. mesh - 3-D mesh surface.

surf - 3-D colored surface. fill3 - Filled 3-D polygons.

Color control . colormap - Color look-up table.

caxis - Pseudocolor axis scaling. shading - Color shading mode.

hidden - Mesh hidden line removal mode. brighten - Brighten or darken color map.

Lighting . surfl - 3-D shaded surface with lighting.

lighting - Lighting mode. material - Material reflectance mode.

specular - Specular reflectance. diffuse - Diffuse reflectance.

surfnorm - Surface normals.

Specialized graphs.Specialized 2-D graphs .

area - Filled area plot. bar - Bar graph.

barh - Horizontal bar graph. bar3 - 3-D bar graph.

bar3h - Horizontal 3-D bar graph. comet - Comet-like trajectory.

errorbar - Error bar plot. ezplot - Easy to use function plotter.

feather - Feather plot. fill - Filled 2-D polygons.

fplot - Plot function. hist - Histogram.

pareto - Pareto chart. pie - Pie chart.

pie3 - 3-D pie chart. Plotmatrix - Scatter plot matrix.

ribbon - Draw 2-D lines as ribbons in 3-D.

stem - Discrete sequence or "stem" plot. stairs - Stairstep plot.

Contour and 2-1/2 D graphs .

contour - Contour plot. contourf - Filled contour plot.

contour3 - 3-D Contour plot. clabel - Contour plot elevation labels.

pcolor - Pseudocolor (checkerboard) plot. quiver - Quiver plot.

voronoi - Voronoi diagram.

Specialized 3-D graphs . comet3 - 3-D comet-like trajectories.

meshc - Combination mesh/contour plot. meshz - 3-D mesh with curtain.

stem3 - 3-D stem plot. quiver3 - 3-D quiver plot.

slice - Volumetric slice plot. surfc - Combination surf/contour plot.

trisurf - Triangular surface plot. trimesh - Triangular mesh plot.

waterfall - Waterfall plot.

Page 12: MATLAB ALL Commands

Addition and Subtraction المصفوفات وطرح جمع

و و المصفوفة كانت إذا

و و و

بالعملية نقومMATLAB باستخدامA , B المصفوفتين لجمعالتالية:

X = A + B

X=

9 2 74 7 105 12 8

التالية: النتيجة ىعل نحصل الناتج منA طرح وعند

Y = X –A

Y =

8 1 63 5 74 9 2

w = v + s

w =

Page 13: MATLAB ALL Commands

9 7 6

ومقلوبها المصفوفات Vector Products and ضربTranspose

A row vector and a column vector of the same length can be multiplied in either order. The result is either a scalar, the inner product, or a matrix, the outer product.

x = v*u

x= 2

X = u*v

X= 6 0— 32 0— 18 0— 4

المصفوفة Matrix transpositionمقلوبX = B'

X= 8 3 41 5 96 7 2

x = v'

x= 20—1

For a complex vector or matrix, z, the quantity z' denotes the complexconjugate transpose. The unconjugated complex transpose is denoted by z.', in analogy with the other array operations. So if

Page 14: MATLAB ALL Commands

z = [1+2i 3+4i]then z' is

1—2i

3—4iwhile z.' is

1+2i3+4i

For complex vectors, the two scalar products x'*y and y'*x are complexconjugates of each other and the scalar product x'*x of a complex vector with

itself is real.

Matrix Multiplication المصفوفات ضرب The matrix product C = AB is

X = A*B

X=

15 15 1526 38 2641 70 39

Y = B*A

Y=

15 28 4715 34 6015 28 43

Page 15: MATLAB ALL Commands

A matrix can be multiplied on the right by a column vector and on the left by

a row vector.

x = A*u

x= 81730

y = v*B

y= 12— 7 10

MATLAB باستخدامGRAPHICS البياني الرسمCreating a Plot

بياني رسم عنه ينتجplot(y) االمر فان متجهة كميةy كانت اذا الرسم عنه فينتجplot(x,y) االمر اما الزمن في كدالةy ل

منy = sin(t) للدالة البياني الرسم اليجاد مثالx وy البيانيالتالية: العملية نجري 2 ى ال0

t = 0:pi/100:2*pi;y = sin(t);plot(t,y)

Page 16: MATLAB ALL Commands

y2 = sin(t–.25);

y3 = sin(t–.5);

plot(t,y,t,y2,t,y3)

باستخدام وذلك مميز وخط بلون منحني كل رسم يمكن

Page 17: MATLAB ALL Commands

plot(x,y,'color_style_marker')

التالية: االحرف نختار اللون الختيار y', 'r', 'g', 'b', 'w', and') اصفر, احمر, اخضر-ازرق-ابيض-اسود(

'k.' ( – – – : –.)التالية: الرموز نختار الخط نوع الختيار

مثالplot(x,y,'y:+')

+ عالمة به منقط اصفر هو الناتج الرسم شكل سيكون

AXIS LABELS البياني الرسم محور علي الكتابةAND TITLES

The xlabel, ylabel, and zlabel functions add x-, y- and z-axis labels. The title function adds a title at the top of the figure and the text function inserts text

anywhere in the figure. t = -pi:pi/100:pi;y = sin(t);

plot(t,y)axis ([-pi pi -1 1])xlabel( '-\pi \leq \itt \leq \pi')ylabel( 'sin(t)')title ('Graph of the sine function')

text(l -1/3, ' \it{Note the odd symmetry. }')

Page 18: MATLAB ALL Commands

Mesh and Surface Plots

MATLAB defines a surface by the z-coordinates of points above a grid in the x-y plane, using straight lines to connect adjacent points. The functions mesh and surf display surfaces in three dimensions. mesh produces wireframe surfaces that color only the lines connecting the defining points. surf displays both the connecting lines and the faces of the surface in color.

Visualizing Functions of Two Variables

To display a function of two variables, z = f (x,y), generate X and Y matrices consisting of repeated rows and columns, respectively, over the domain of the function. Then use these matrices to evaluate and graph the function. The meshgrid function transforms the domain specified by a single vector or two vectors x and y into matrices X and Y for use in evaluating functions of two variables. The rows of X are copies of the vector x and the columns of Y are copies of the vector y. To evaluate the two-dimensional

sinc function, sin(r)/r, between x and y directions:

[X,Y = ]meshgrid(–8:.5:8);

Page 19: MATLAB ALL Commands

R = sqrt(X.^2 + Y.^2) + eps;Z = sin(R)./R;

mesh(X,Y,Z)

In this example, R is the distance from origin, which is at the center of the matrix .

Adding eps avoids the indeterminate 0/0 at the origin.

Printing Graphics

The Print option on the File menu and the print command both print

MATLAB figures .

MORE ABOUT MATRICES AND ARRAYS

This sections shows you more about working with matrices and arrays, focusing on

• Linear Algebra • Arrays • Multivariate Data

Linear Algebra

Informally, the terms matrix and array are often used interchangeably. More precisely, a matrix is a two-dimensional numeric array that represents a linear transformation. The mathematical operations defined on matrices are the subject of linear algebra. Dürer’s magic square

Page 20: MATLAB ALL Commands

A= 16 3 2 13

5 10 11 89 6 7 12

4 15 14 1provides several examples that give a taste of MATLAB matrix operations. You’ve already seen the matrix transpose, A'. Adding a matrix to its

transpose produces a symmetric matrix.A + A'

ans= 32 8 11 17

8 20 17 2311 17 14 2617 23 26 2

The multiplication symbol, *, denotes the matrix multiplication involving inner products between rows and columns. Multiplying a matrix by its

transpose also produces a symmetric matrix.A'*A

ans= 378 212 206 360212 370 368 206206 368 370 212360 206 212 378

PARTIAL-FRACTION EXPANSION WITH MATLAB

MATLAB has a command to obtain the partial-fraction expansion of B(s)/A(s). Consider the transfer function

Page 21: MATLAB ALL Commands

where some of ai and bj may be zero. In MATLAB row vectors num and den specify the coefficients of the numerator and denominator of the transfer

function. That is,

num = [b0 b1 ... bn ] den = [1 a1 ….an ]

The command

[r,p,k = ]residue(num,den)

finds the residues, poles, and direct terms of a partial-fraction expansion of

the ratio of two polynomials B(s) and A(s).The partial-fraction expansion of B(s)/A(s) is given by

Comparing this equation with the following

we note that p(1) = -p1, p(2) = -p2 ,....... p(n) = -pn; r(1)= a1, r(2) = a2,….. r(n) = an

[k(s) is a direct term].

EXAMPLE: Consider the following transfer function:

num = [2 5 3 61 den = [1 6 11 6]

[ r;p,k = ]residue(num,den)

Page 22: MATLAB ALL Commands

The command gives the following result: [r,p,k = ]residue(nurn,den)

r = -6.0000

- 4.0000 3.0000

p = -3.0000

-2.0000 -1.0000

2k=

(Note that the residues are returned in column vector r, the pole locations in

column vector p, and the direct term in row vector k ).

This is the MATLAB

representation of the following partial-fraction expansion of B(s)/A(s),

The command

[num1den = ]residue(r;p,k)

where r, p and k are as given in the previous MATLAB output, converts the partial-fraction expansion back to the polynomial ratio B(s)/A(s), as follows:

[num,den = ]residue(r,p,k)num=

2.00005.00003.00006.0000

den= 1.00006.000011.00006.0000

Note that if p(j) = p(j + 1) =…..= p(j + m - 1) [that is,pj = pj+1 =…= pj+m-1], the pole p(j) is a pole of multiplicity m. In such a case, the expansion includes terms of the form

Page 23: MATLAB ALL Commands

r(j) + r(j + 1) +….+ r(j + m - 1) s - p(j) [s -p(j)]2 [s-p(j)]m

EXAMPLE. Expand the following B(s)/A(s) into partial-fractions with

MATLAB.

B(s) = s 2 +2s + 3 = s2 + 2s + 3… A(s) (s + 1)3 s3 + 3s2 + 3s + 1

For this function, we have

num = [0 1 2 3] den = [1 3 3 1]

The command

[r,p,k = ]residue(num,den)

gives the result shown below . num = [0 1 2 3] ;

den = [1 3 3 1];[ r,p,k = ]residue(num,den)

r= 1.00000.00002.0000

p= -1.0000-1.0000-1.0000

k= ] [

And it is the MATLAB representation of the following partial-fraction

expansion of B(s)/A(s):

Page 24: MATLAB ALL Commands

Note that the direct term k is zero.

Transient response analysis with Matlab

Consider the system :

(1)

This system is represented as two arrays each containing the coefficients of the polynomials in decreasing powers of s as follows

num = [0 0 251den = [1 4 25]

Note that zeros are padded where necessary. If num and den (the numerator and denominator of the closed-loop transfer function) are known, commands such as

step(num,den),step(num,den,t)

will generate plots of unit-step responses. (t in the step command is the user-specified time.) For a control system defined in a state-space form, where state matrix A, control matrix B, output matrix C, and direct transmission matrix D of state-space equations are known, the command

step(A,B,C,D)

will generate plots of unit-step responses. The time vector is automatically determined when t is not explicitly included in the step commands Note that when step commands have left-hand arguments such as

[y,x,t = ]step(nun,den,t)

Page 25: MATLAB ALL Commands

[y,x,tl = step(A,B,C,D,iu)Iy,x,tj = slep(A,B,C,D,iu,t)

no plot is shown on the screen. Hence it is necessary to use a plot command to see the response curves. The matrices y and x contain the output and state response of the system, respectively, evaluated at the computation time points t. (y has as many columns as outputs and one row for each element in t. x has as many columns as states and one row for each element in t.) Note in Equation (2) that the scalar U is an index into the inputs of the system and specifies which input is to be used for the response. and t is the user-specified time. If the system involves multiple inputs and multiple output the step command, such as given by Equation (4-39), produces a series of step response plots, one for each input and output combination of

x =Ax+Buy = Cx + Du

Obtaining the unit-step response of the transfer-function system. let us consider the unit-step response of the system given by Equation (1). The

MATLAB Program for this system is .

num= [0 0 25];den = [1 4 25];step(num,den)

gridtitle ('Unit-step Response of G(s)=25/(s^2+4s+25)')

A plot of the unit step response curve is shown below:

Page 26: MATLAB ALL Commands

Example

Obtain the unit-impulse response of the following system:

A possible MATLAB program is shown below. The resulting response curve is also shown below.

A = [0 1;-1 -1];

B = [0;1l;

C= [1 0];

D = [0];

impulse(A,B,C,D);

grid;

title('Unit-Impulse Response')

Page 27: MATLAB ALL Commands

Example : Obtain the unit-impulse response of the following system:

num= [0 0 1];den = [1 0.2 1];

impulse(num,den)gridtitle ('Unit- impulse Response of G(s)=1/(s^2+0.2s+1)')

Page 28: MATLAB ALL Commands

Example:Consider the impulse response of the standard second-order system defined by

For a unit-impulse input, R(s) = 1. Thus

Consider the normalized system where Wn= 1. Then

Consider five different values of zeta: = 0.1, 0.3, 0.5, 0.7, and 1.0. Obtain

the unit-impulse response curves for each zeta with MATLAB.Solution. A MATLAB program for plotting the five unit-impulse response

curves in one diagram is

Num=[0 1 0];den=[1 0.2 1];t=0:0.1:10;step(num,den1,t);

text(2.2,0.88,'zeta=0.1')hold

den2= [1 0.6 1]; den3= [1 1 1]; den4= [1 1.4 1]; den5= [1 2 1];step(num,den2,t);

text(1.33,0.72.'0.3')

step(num,den3,t);text(1.15,0.58.'0.5')

step(num,den4,t);text(1.1,0.46.'0.7')

Page 29: MATLAB ALL Commands

step(num,den5,t);text(0.8,0.28.'1.0')gridtitle(Impulse-responseCurves for G(s)=1/[s^2+2(zeta)s+1]')hold

The resulting diagram is shown below:

From the unit-impulse response curves for different values of zeta, we may conclude that if the impulse response c(r) does not change sign the system is either critically damped or overdamped, in which case the corresponding step response does not overshoot, but increases or decreases monotonically and approaches a constant value.

Response To torque disturbances (Proportional control)

Page 30: MATLAB ALL Commands

Obtain responses of the above system with MATLAB when it is subjected to a unit-step disturbance. for a small value of Kp and a large value of Kp.

Consider two cases:

Case l:

J=1, b=0.5, Kp=1 (system 1):

Case 2:

J = 1, b = 0.5, Kp = 4 (system 2):

Note that for system 1

num1 = [0 0 1]den1= [1 0. 5 1]

For system 2

num2 = [0 0 1]

den2 = [1 0.5 4]

In MATLAB Program we have used notations y1 and y2 for the response. yl is the response c(t) of system 1, and y2 is the response c(t) of system 2.

In MATLAB Program 5-1, note that we have used the plot command with multiple arguments, rather than using the hold command. (We get the same result either way.) To use the plot command with multiple arguments, the sizes of the y1 and y2 vectors need not be the same. However, it is convenient if the two vectors are of the same length. Hence, we specify the same number of computing points by specifying the computing time points (such as t = 0:0.1:20). The step command must include this user-specified time t. Thus, in MATLAB Program 5-1 we have used the following step command:

[y, x, t = ]step(num, den,t)

The unit-step response curves obtained by use of MATLAB Program are shown below.

Page 31: MATLAB ALL Commands

num 1 = [0 0 1];

den1 = [1 0.5 1] ;

num2 [0 0 1] ;

den2 [1 0.5 4];

t = 0:0.1:20;

[y1,x1,t = ]step(num l, den l, t) ;

[y2,x2,t = ]step(num 2,den2,t) ;

plot(t,yl,t,y2)gridtext(1 1,0.75,'System 1'), text (11.2,0.1 6,'System 2')title('Step Responses of Two Systems'')xlabel('t Sec')ylalbel(toutputs yl and y2')

ROOT-LOCUS PLOTS WITH MATLAB

Page 32: MATLAB ALL Commands

In this section we present the MATLAB approach to the generation of root-locus plots.

Plotting root loci with MATLAB. In plotting root loci with MATLAB we deal

with the system equation given in the form of

Which may be written as :

Were num is the numerator polynomial and den is the denominator polynomial. That is,

num = (s + z1)(s +z2 )..... (s + zm) =sm +(z1+z2+….+zm)sm-1+…+z1z2….zm

den = (s + p1)(s+p2) ....... (s + pn) =sn + (p1 +p2+…. +pn)sn-1 +... +p1 p2 ….pn

Note that both vectors num and den must be written in descending powers of s A MATLAB command commonly used for plotting root loci is

rlocus(num,den)Using this command, the root-locus plot is drawn on the screen. The gain vector K is automatically determined. The command rlocus works for both continuous- and discrete-time systems. For the systems defined in state space, rlocus(A, B,C, D) plots the root locus of the system with the gain vector automatically determined. Note that commands

rlocus(num,den,K) and rlocus(A,B,C,D,K) use the user-supplied gain vector K. (The vector Kcontains all the gain values for which the closed-loop poles are to be computed.) If invoked with left-hand arguments

[r,K = ]rlocus(num,den)[r,K = ]rlocus(num,den,K)

[r,KI = rlocus(A,B,C,D)

Page 33: MATLAB ALL Commands

[r,Kl = rlocus(A,B,C,D,K)

the screen will show the matrix r and gain vector K. (r has length K rows and length den - 1 columns containing the complex root locations. Each row of the matrix corresponds to a gain from vector K.) The plot command plot(r,' ') plots the root loci. If it is desired to plot the root loci with marks '0'' or 'x', it is necessary to use the following command:

r = rlocus(num,den)pIot(r,'o') orpIot(r,'x')

EXAMPLE Consider the control system shown below. To plot the root-locus

diagram with MAT-LAB, it is necessary to find the numerator and denominator polynomials of the open loop.

For this problem, the numerator is already given as a polynomial in s. However, the denominator is given as a product of first- and second-order terms, with the result that we must multiply these terms to get a polynomial in S. The multiplication of these terms can be done easily by use of the convolution command, as shown next.

Define

a = s(s +4) = s2 + 4s : a = [1 4 0]b= s+6 : b= [1 6]c = s2 + 1.4s + 1 : c= [1 1.4 1]

Then use the following command:

d = conv(a,b);

Page 34: MATLAB ALL Commands

e = conv(c,d)

[Note that conv(a,b) gives the product of two polynomials a and b ].

a = [1 4 0];

b = [1 6];

c = [1 1.4 1];

d = conv(a,b)d=

1 10 24 0

e = conv(c,d)e=

1.000011.4000 39.0000 43.6000 24.0000 0

The denominator polynomial is thus found to be

den = [1 11.4 39 43.6 24 0]

To find the open-loop zeros of the given transfer function, we may use the following roots command:

p = [1 2 4]r = roots(p)

r=

-1.0000 + 1.7321I-1.0000 - 1.7321I

Similarlv, to find the complex-conjugate open-loop poles (the roots of s2 + 1.4s + 1 = 0), we mav enter the roots commands as follows:

q = roots(c)q=

-0.7000 +0.7141i-0.7000 -0.7141i

The MATLAB Program will be as shown:

num =[0 0 0 1 2 4];

den = [1 11.4 39 43.6 24 0];

Page 35: MATLAB ALL Commands

rlocus(num,den)grid

title('Root-locus Plot of G(s)=K(s^2+2s+4)/[s(s+4)(s+6)(s^2+1.4s+1)]')

EXAMPLE:

Consider the system shown below, where the open-loop transfer function G(s)H(s) is

The MATLAB Program generates a root-locus plot is as shown .

num = [0 0 1 0.2] ;

den = [1 3.6 0 0] ;

rlocus(num,den)v= [-4 2 -4 4]; axis(v)

Page 36: MATLAB ALL Commands

gridtitle(~Root-Locus Plot of G(s) = K(s + 0.2)/[s^2(s + 3.6)]')

The resulting root-locus plot is

EXAMPLE

Consider the system shown.

Plot root loci with a square aspect ratio so that a line with slope 1 is a true 450 line.

To set the plot region on the screen to be square, enter the command axis('square'). With this command, a line with slope 1 is at a true 45º, not skewed by the irregular shape of the screen. MATLAB Program which produces a root-locus plot in a square region is.

num = [0 0 0 1 1];

den = [13 12 -16 0[;

rlocus(num,den}

v = [-66 -661; axis(v);axis('square1)

Page 37: MATLAB ALL Commands

gridtitle('Root-Locus Plot of G(s) = K(s + 1 )/[s(s - 1 )(s^2 + 4s + 1 6)]')The resulting plot is.

EXAMPLE:

Consider the system whose open-loop transfer function G(s)H(s) is

There are no open-loop zeros. Open-loop poles are located at 5 = -0.3 + j3.1480, 5 = -0.3 -j3.1480,s = -0.5~ands = 0.

MATLAB Program

num=[0 0 0 0 1];

den = [1 1.1 10.3 5 0] ;

rlocus(n urn , den)grid

title(' Root-Locus Plot of G(s) = K/[s{s + 0.5)(s^2 + 0.6s + 10))']

the root-locus plot.

Page 38: MATLAB ALL Commands

Example : Consider the control system shown.

Plot root loci with MATLAB.

Solution .

MATLAB Program

num = [0 0 1 0.41 ;

den = [1 3.6 0 0] ;

rlocus(num,den;}

V = [-5 1 -3 3]; axis(v)

Page 39: MATLAB ALL Commands

gridtitle(' Root-Locus Plot of C(s) = K(s + O.4)/[s^2(s + 3.6)]'))

PLOTTING BODE DIAGRAMS WITH MATLAB

The command bode computes magnitudes and phase angles of the frequency response of continuous-time, linear, time-invariant systems. When the command bode (without left-hand arguments) is entered in the computer, MATLAB produces a Bode plot on the screen. When invoked with left-band arguments, [mag,phase,w] = bode(num,den,w) bode returns the frequency response of the system in matrices mag, phase and w- No plot is drawn on the screen-The matrices mag and phase contain magnitudes and phase angles of the frequency response of the system evaluated at user specified frequency points. The phase angle is returned in degrees. The magnitude can be converted to decibels with the statement magdB = 20*Iogl0(mag) To specify the frequency range, use the command Iogspace(d1 ,d2) or Iogspace (d1 ,d2,n). logspace(dl ,d2) generates a vector of 50 points logarithmically equally spaced between decades 10d1 and 10d2. That is, to generate 50 points between 0.1 rad/sec and100 rad/sec, enter the command w = logspace(-1,2).

logspace(d1 ,d2,n) generates n points logarithmically equally spaced between decades 10d1 and 10d2 For example, to generate100 points between 1

Page 40: MATLAB ALL Commands

rad/sec and 1000 rad/sec, enter the following command: w = Iogspace(0,3,100) To incorporate these frequency points when plotting Bode diagrams, use the command bode(num,den,w) or bode(A,B,C,D,iu,w).These commands use the user-specified frequency vector w .

Example1:

Consider the following transfer function:

524

52()

2

sssG

Plot a Bode diagram for this transfer function. When the system is defined in the form

G(s) = den(s), num(s)

use the command bode(num,den) to draw the Bode diagram. [when the numerator and denominator contain the polynomial coefficients in descending powers of s, bode(num,den) draws the Bode diagram.] MATLAB Program to plot the Bode diagram for this system is .

num [0 0 25)

den [1 4 25],

bode(num,den)subplot[2 1 1]title(' Bode Diagram of G(s)=25/(s^2+4s+25)')

The resulting Bode diagram is.

Page 41: MATLAB ALL Commands

Example 2:

Plot a bode diagram for a system with the open-loop transfer function of:

(92.1)

(12.0)9()

2

2

sss

sssG

MATLAB Program.

num = [0 9 1.8 9]den =[1 1.2 9 0];

bode(num,den)subpIot(2,1,1) ;

title('Bode Diagram of G(s) = 9(s^2 + 0.2s+1)/[s(s^2+1.2s + 9)]'))

The resulting plot is .

Page 42: MATLAB ALL Commands

The frequency range in this case is automatically determined to be from 0.1 to 10 rad/sec. If it is desired to plot the Bode diagram from 0.1 to 1000 rad/sec, enter the following command; w = logspace(-2,3,100) This command generates 100 points logrithmically equally spaced between 0.01 and 100 rad/sec. (Note that such a vector w specifies the frequencies in radians per sccond at which the frequency response will be calculated.) If we use the command bode(num,den,w) then the frequency range is as user specified, but the magnitude range and phase-angle range will be automatically determined.

Obtaining Bode diagrams of systems defined in state space .

Consider the system defined by

X' = Ax + Buy = Cx + Du

wherex = state vector (n-vector)y = output vector (m-vector)u = control vector (r-vector)A = state matrix (n x n matrix)B = control matrix (n x r matrix)

Page 43: MATLAB ALL Commands

C = output matrix (m x n matrix)D = direct transmission matrix (m x r matrix)

A Bode diagram for this system may be obtained by entering the command

bode(A,B,C,D) or bode(A,B,C,D,iu)

The command bode(A,B,C,D) produces a series of Bode plots, one for each input of the system, with the frequency range automatically determined. (More points are used when the response is changing rapidly.) The command bode(A, B,C,D,iu) where iu is the ith input of the system, produces the Bode diagrams from the input iu to all the outputs (y1, y2,---, ym) of the system, with frequency range automatically determined. (The scalar iu is an index into the inputs of the system and specifies which input is to be used for plotting Bode diagrams). If the control vector u has three inputs such that

3

2

1

u

u

u

u

then iu must be set to either 1,2, or 3. If the system has only one input u,then either of the following commands may be used:

bode(A,B,C,D) or bode(A,B,C,D,1)

Example 3: Consider the following system :

ux

x

x

x

52

0

452

10

2

1

'2

'1

2

101x

xy

This system has one input u and one output y. Then the MATLAB Program is:

A = [0 1; -25 -4];

B = [0;25];

Page 44: MATLAB ALL Commands

C = [1 0];

D = [0];

Bode(A,B,C,D)Subplot(2,1,1);

Title('Bode Diagram')

we obtain the Bode diagram shown as shown below:

If we replace the command bode(A,B,C,D) in MATLAB Program with bode(A,B,C,D,1)then MATLAB will produce the Bode diagram identical to that shown above.