SlideServe
Menu
Préférences
© SlideServe · v2026

M ATLAB B ASICS

nash avatar
66 diapositives · 875 Views · Oct 15, 2014

M ATLAB B ASICS. Sanjay R Joshi sanjayrjoshi@yahoo.com 18-July-2005 MATLAB for ELECTRICAL ENGINEERING ELECTRICAL ENGINEERING DEPARTMENT L.D.COLLEGE OF ENGINEERING AHMEDABAD. MATLAB - developed by Math Works Inc. http://www.mathworks.com

M ATLAB B ASICS - slide 1
01 / 66M ATLAB B ASICS
1 / 17

Télécharger la présentation

M ATLAB B ASICS
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. MATLABBASICS Sanjay R Joshi sanjayrjoshi@yahoo.com 18-July-2005 MATLAB for ELECTRICAL ENGINEERING ELECTRICAL ENGINEERING DEPARTMENT L.D.COLLEGE OF ENGINEERING AHMEDABAD

  2. MATLAB - developed by Math Works Inc. • http://www.mathworks.com • MATLAB - acronym for MATrix LABoratory • Matrices and arrays - the heart of MATLAB • Offers programming features - similar to other languages • Offers GUI tools

  3. Why MATLAB is popular ? • No need to declare dimensions of a matrix as in FORTRAN or C. • Very powerful and easy-to-learn graphics capabilities. • MATLAB can be integrated with FORTRAN and C/C++ programs. • MATLAB has many toolboxes (collections of MATLAB functions) applied to specific topics like control system, symbolic manipulation, FFT etc. • MATLAB has proved to be extremely efficient and hence very fast for solving some problems.

  4. MATLAB is an interactive system for doing numerical computations • Powerful operations can be performed using just one or two commands. • There are more than 1000 functions in the basic MATLAB product alone. • Modeling, simulation, Data analysis, exploration, and visualization and many more. • Application development, including Graphical User Interface building.

  5. Easy to use Platform independence Predefined functions Device –independent plotting

  6. MATLAB WINDOWS COMMAND WINDOW To give MATLAB commands at the prompt EDIT/DEBUG WINDOW To create , edit and debug the program. Type edit at the command prompt. FIGURE WINDOW To visualize graphs and plots

  7. Provides a variety of graphic output displays: • linear • log-log • semilog • polar • bar chart, and • contour plots • 2-D and 3-D views

  8. Provides extensive numerical resources • Over 200 reliable, accurate mathematical subprograms • The subprograms provide solutions to broad range of mathematical problems including: matrix algebra ( Linear Algebra ) • complex arithmetic • differential equations • nonlinear systems, and • many special functions

  9. Available in all operating systems: • DOS • Windows9.x/NT • Unix • Macintosh • Same syntax for all platforms • Open system environment - access to source code • Allows - to mix MATLAB with FORTRAN or C

  10. Simple Math » 2+2.5+106 ans = 110.5000 » 4*25 + 2^3 ans = 108 » One can use it as a calculator/scratch pad

  11. MATLAB Variables » a = 2 a = 2 »b = 3 b= 3

  12. MATLAB Variables » c = 1000; » d = 0.001; » e = a*b*c/d e = 6000000 »

  13. MATLAB Variables • MATLAB variable are automatically created • when they are initialized. • There are three way to initializing variable in MATLAB. • Assign data to the variable in an assignment statement. Input data into the variable from the keyboard. Read data from file.

  14. MATLAB Workspace To recall the variable » a a = 2 » Use arrow keys for scrolling through previous commands

  15. MATLAB Workspace List of variables in the workspace » who Your variables are: a b c d e »

  16. Variable Naming Rules • Variable names are case sensitive. For example NRe and nRe are different MATLAB variables • Variable name can contain upto 31 characters. • Start with a letter, followed by letters, numbers or underscores. • For example: SRe_2_electrical_power2by3

  17. Special Variables

  18. To Clear a Variable » who Your variables are: a b c d e » clear a; » who Your variables are: b c d e

  19. To clear all variables » who Your variables are: b c d e » clear » who »

  20. Complex Numbers » i ans = 0 + 1.0000i » c1 = 2+3i c1 = 2.0000 + 3.0000i »

  21. Mathematical Functions » x=sqrt(2)/2 x = 0.7071 » y=sin(x) y = 0.6496 »

  22. Built-in Functions

  23. Saving & Loading Data >> A=[2 0; 0 5]; >> [M l]=eig(A); >> save data1 M l; clear all; >> who >> load data1 >> who Your variables are: M l

  24. Array Operations » x = [1 2 3 4 5 6 7 8 9 10] x = 1 2 3 4 5 6 7 8 9 10 » a = 1:2:10 Note : operator a = 1 3 5 7 9

  25. Array Operations » y = sin(x) y = Columns 1 through 7 0.8415 0.9093 0.1411 -0.7568 -0.9589 -0.2794 0.6570 Columns 8 through 10 0.9894 0.4121 -0.5440

  26. Array Addressing » y(3) ans = 0.1411 » y(1:5) ans = 0.8415 0.9093 0.1411 -0.7568 -0.9589

  27. Array Orientation » z = [1; 2; 3; 4] z = 1 2 3 4 » z' ans = 1 2 3 4

  28. Array Manipulation » A = [1 2; 3 4; 5 6] A = 1 2 3 4 5 6 » B = [1 2 3; 4 5 6]; » A+B ??? Error using ==> + Matrix dimensions must agree. »

  29. Array Manipulation » A*B ans = 9 12 15 19 26 33 29 40 51

  30. Significance of . » clear » A = [1 2; 3 4]; » B = [1 1; 2 2]; » A.*B ans = 1 2 6 8 »

  31. Significance of . » A./B ans = 1.0000 2.0000 1.5000 2.0000 » A/B Warning: Matrix is singular to working precision. ans = Inf Inf Inf Inf»

  32. Matrix Operations » [A B] ans = 1 2 1 1 3 4 2 2 » ans-1 ans = 0 1 0 0 2 3 1 1 »

  33. Matrix Operations >> G= A - B G = 0 1 1 2 >> D = A +B D = 2 3 5 6

  34. Matrix Operations » C = [A B] C = 1 2 1 1 3 4 2 2 » C(1,:) ans = 1 2 1 1 » » C(:,2) ans = 2 4 » C(:,2:end) ans = 2 1 1 4 2 2 »

  35. Matrix Functions » size(C) ans = 2 4 » determ(A) ans = -2 » » A A = 1 2 3 4 » inv(A) ans = -2.0000 1.0000 1.5000 -0.5000

  36. Matrix Functions Some functions: determ, inv, diag, triu, tril, rank, eig, size » eig(A) ans = -0.3723 5.3723 Show eigshow » [a b] = eig(A) a = -0.8246 -0.4160 0.5658 -0.9094 b = -0.3723 0 0 5.3723

  37. Standard Arrays » eye(2) ans = 1 0 0 1 » eye(2,3) ans = 1 0 0 0 1 0 » Other such arrays: ones(n), ones(r, c) zeros(n), zeros(r, c) rand(n), rand(r,c)

  38. ones(3) ans = 1 1 1 1 1 1 1 1 1 >> ones(3,2) ans = 1 1 1 1 1 1 zeros(2) ans = 0 0 0 0 >> zeros (3,2) ans = 0 0 0 0 0 0 Standard Arrays

  39. Plots » x = 1:2:50; » y = x.^2; » plot(x,y) »

  40. Plots » plot(x,y,'*-') » xlabel('Values of x') » ylabel('y') »

  41. Relational Operators < > <= >= == ~=

  42. Control Flow Statements for n=1:10 … end while expression … end if expression … else ... end

  43. MATLAB Files M-files Script Files Function Files MAT-files MEX-files

  44. M Files M-files are ordinary ASCII (text) files having extension .m containing MATLAB commands

  45. SCRIPTS Variables created by scripts remains in workspace even after the execution of it. Create a script file and edit it in MATLAB Editor called M-File Editor e.g % This is a sample Script M-file A = [ 1 2 3; 4 7 1; 9 5 0]; [x,v] = eig(A)

  46. Note script here

  47. Using Script M-files » what M-files in the current directory C:\WINDOWS.000\Desktop\MEE\ASSIGN-1 solu_AC_Series_Ckt » solu_AC_Series_Ckt