Week 10: Introduction to important software and tools

  • Upload
    jacie

  • View
    19

  • Download
    0

Embed Size (px)

DESCRIPTION

SEE1012: Introduction to Electrical Engineering. Week 10: Introduction to important software and tools. 1. Introduction to PSpice 2. MATLAB for Engineering Applications. The materials are extracted from: 1. http:// stuweb.ee.mtu.edu 2. http://www.osc.edu/. Introduction to PSpice. - PowerPoint PPT Presentation

Citation preview

Slide 1

Week 10:Introduction to important software and toolsSEE1012: Introduction to Electrical Engineering1. Introduction to PSpice

2. MATLAB for Engineering Applications

The materials are extracted from: 1. http://stuweb.ee.mtu.edu2. http://www.osc.edu/2Basic Information: restrooms--through the hall to the right, found on the right sign the sheet by the door, get booklet, sign up for userid and password ask questions; will try to answerOSC--facilities for high performance computingSTS Group: supports users; tests systems; develops courses; participates in national collaborationstechnical Web page: http://www.osc.edu/supercomputingIntroduction to PSpice3The Origins of SPICESPICE developed in the 1970sSimulation Program with Integrated Circuit EmphasisDeveloped to save moneySimulation of circuits, not physically buildingTransistor sizesMicroprocessors vs. 2N2222

4After the CANCER project, the next innovation was the SPICE program. SPICE stands for Simulation Program with Integrated Circuit Emphasis. This new acronym was created from the fact that many of the components being placed on the new integrated circuit were becoming smaller than the discrete components themselves. With this in mind, the SPICE creators wanted to save money by not having to manufacture chips to test the circuits. The next logical step was to let a computer do the testing for them.By not building the physical circuit, the designers can save a lot of time and money.This Is NowNew user interfaceGraphical circuit diagramsVariation of simulation parameters with a few clicks

5The advances in Operating systems on computers gives program designers the freedom to make Graphical User Interfaces like that shown above. This makes the programming of the simulation simpler than that of the old days. The old days required the knowledge of the syntax of all the components along with all the different simulation calculations. Now a days, the circuit simulation results can be viewed with a click of a button, or with the placement of a few probes. To get the output graphs it takes a few changes in some of the settings, but that is a very simple task with the mouse.

First Look at Capture

First window you will see when you open CaptureCreate a new ProjectFile New ProjectThis will open a new window6First, we will want to open Capture from the start menu. The default installation directory may have been changed, so youll want to look for something that indicates that CAPTURE or PSPICE. Then you will want to open the CAPTURE STUDENT Shortcut. This will open the window above. Next you will want to use the File -> New -> Project to create a new project.Select a project namePSpice Lab SimulationSelect a project locationC:\PSpice\{YourName}Select what type of projectAnalog or Mixed A/DClick OK

New Project Window

7This is the new window that you will get. First we want to type in a project name. Type in PSpice Lab Simulation into the Name field. The window will then look like this. The next step will be to find a location to save the project. You can either type in the path location or use the Browse button to find a location. If you use the browse button you can create a new folder with your name to save the lab. If you know the exact path of a file you want to save too, type this full path into the location field. The window will then look like this. Make sure that the Analog or Mixed A/D is selected then the last step is to click the OK button.Create PSpice Project

This window will openSelect the bottom optionCreate a blank projectClick OK8This window is used to make projects from an already created project. This acts like a template and will allow many of the same projects to be made from one common project. In this window select Create a Blank Project and then click Ok.The Project WindowsThe Main Project WindowTwo other information windowsSession Log WindowProject File WindowOur main windowSchematic 1: Page 1

9This is the project workspace. This main window has three sub windows. The window on the left is titled Your Project Name. If everything was followed up to this point, it will read PSpice Lab Simulation. The next window on the far top right, is the session log window. This window will inform you of what is happening in your project session. For our purposes we will not need that window. The most important window in this screen is that of the circuit. It is titled Schematic 1: Page 1. This is where our part will be placed for the simulation. This is what makes PSpice now days better than the old days.Place Parts

Place the 5 resistorsUsing Place PartType R in Part FieldPlace the Voltage SourceUsing Place PartType Vdc in Part FieldRight click and choose End Mode10Now that we know where the parts are to be placed, we can start to place them. Click on the Schematic 1 window to make that the active window (just to show the point, you can click on the other windows and the menus will change). Next, use the Place, Part command, and in the Part field, type in R. This will select the Resistor part. Click on the OK button that appears and place 5 resistors. Repeat the Place, Part command, and in the Part field type in Vdc. This will select the DC Voltage source. Click the OK button and place the DC Voltage source. Right click and choose End Mode.Rotate and Move ResistorsClick on the resistorUse Ctrl+R to rotateRepeat for 4 resistorsMove and place the resistors in parallelChange the valuesDouble Click on the 1k and enter 4k of the parallel resistors

11Now we need to move the resistors so that they are arranged with one in series and 4 in parallel. This is done by clicking and dragging the resistors to the correct spot. But the resistors are in the wrong orientation, so we can fix that by clicking on a resistor and pressing Control+R. We can also do this by first selecting a resistor and then right clicking and choose rotate. Repeat this until the circuit looks like the following. Now we have to change the values of the resistors. This can be done by double clicking on the value of the resistor. The default value of the resistors are 1k. We want to change the four parallel resistors to 4k. After double clicking on the value type in 4k into the value field. Repeat for the four parallel resistors.Change the Voltage and Wire

Change DC VoltageDouble Click on 0Vdc and enter 16VdcNow wire the circuitUsing Place WireClick on one node, and draw to the other and click againRight click and select End Mode12Next, we want to change the value of the DC voltage source. This is done in the same way that the values of the resistors were changes. Double click on the default value of 0Vdc for the power supply and enter 16Vdc. The next step is to wire the circuit. This can be done with the Place, Wire command. Placing wire is fairly easy. Click on one node of the circuit, and then draw to the other node. Once there, click the mouse again. Repeat until the circuit is completely wired as shown above.Placing the GroundEvery PSpice circuit must have a groundUse the icons on the right9th icon down This opens the Place Ground windowSelect the 0/SourceClick OK

13The next step in the circuit is to place a ground. This is required for every circuit simulation in Capture or PSpice. If there is no ground, the simulation will give Node is Floating errors, and will not work. Use the Place Ground icon on the right side of the screen, and open the window above. Make sure that the Source library is in the Libraries field. If not, ask for help. Then select the 0/source ground, and click ok. Place the ground on the circuit near the bottom and then right click and choose End Mode. Then wire the bottom of the circuit to the ground using the Place, Wire command. The circuit should now look like the next slide.The Completed Circuit

14This is the completed circuit. Notice that this is a very simple resistive circuit. When you do the prelab for this circuit you will be able to determine the voltages and currents. For now, we will go through the demonstration of how to run the simulation, but will withhold the results until lab time.Simulation ProfileNeed to create a simulation profilePSpice New Simulation ProfileName the profileDC SolutionClick OK

15The simulation profile is what allows us to vary how we can simulate the circuit. There are many different things we can change to make the simulation fit our needs. In this straight forward example we are just going to be working with the DC Solution, and all that is required is the Bias Point. So, type in a name for your Simulation Profile and make sure none is in the Inherit From box. Click OK to continue.Edit the Simulation ProfileGo to the Analysis TabUnder the Analysis type, choose Bias PointThis is to find the DC solutionClick OKReady to Simulate

16Once the simulation profile window is open, take a look around at all the different options you can change. Make sure not to change anything right now though. We are interested in the Analysis tab which should be selected by default. Now choose Bias Point under the Analysis Type. This will get the DC Solution that we are looking for. Once this is done, you can click the OK button to return to the Schematic window.Running the SimulationThe last step is to RUN the simulationDo this by selecting PSpice RunAfter running the simulation a new window will openClose this window and return to the Schematic 1: Page 1 windowUse the V and I (and maybe W) icons on the top of the screen For finding voltages and currents (and power)17Now that the simulation profile is set up, and the circuit is complete, we are now ready to run the simulation. You can do this by choosing the PSpice, Run command. This will open a new window that is not very useful for this simulation, so close that window. Now there are icons near the top of the screen that have V and I (and if the version is high enough, a W icon too). Once the simulation is complete, you can click these buttons on and off, to view the voltages at the nodes and the currents through the components.Now You KnowWith this basic underlying knowledgeCan changeResistor valuesVoltage supply valuesResistor configurationCan learnMore simulation parametersMore components for simulation18Now that we have the basics of DC circuits down, we can change things up a little bit. We can vary the resistor values, the supply voltages and even how the resistors are connected. There is a lot of room to improve on this basic principle of resistor circuits though. You can look through the parts list to see what type of components are available. There are many digital chips and even more analog parts. So, in the future we can learn what the other parameters in the simulation profile can do and on top of that add more components like Capacitors, Inductors, Transistors, Diodes, and many other. Now that you have this basic knowledge, we can go off to lab and make use of this information. That is an introduction to PSpice, and you will use this program more in your Electrical Engineering careers.Introduction to MatlabIntro MATLABMATLABs AppealInteractive code development proceeds incrementally; excellent development and rapid prototyping environmentBasic data element is the auto-indexed arrayThis allows quick solutions to problems that can be formulated in vector or matrix formPowerful GUI toolsLarge collection of toolboxes: collections of topic-related MATLAB functions that extend the core functionality significantly

20Intro MATLABMATLAB ToolboxesSignal & Image Processing Signal Processing Image Processing Communications Frequency Domain System Identification Higher-Order Spectral Analysis System Identification Wavelet Filter Design

Control Design Control System Fuzzy Logic Robust Control -Analysis and Synthesis Model Predictive Control

Math and AnalysisOptimizationRequirements Management InterfaceStatisticsNeural NetworkSymbolic/Extended MathPartial Differential EquationsPLS ToolboxMappingSpline

Data Acquisition and ImportData AcquisitionInstrument ControlExcel LinkPortable Graph Object21Intro MATLABToolboxes, Software, & Links

22Intro MATLABMATLAB SystemLanguage: arrays and matrices, control flow, I/O, data structures, user-defined functions and scriptsWorking Environment: editing, variable management, importing and exporting data, debugging, profilingGraphics system: 2D and 3D data visualization, animation and custom GUI developmentMathematical Functions: basic (sum, sin,) to advanced (fft, inv, Bessel functions, )API: can use MATLAB with C, Fortran, and Java, in either direction23Intro MATLABOnline MATLAB Resourceswww.mathworks.com/www.mathtools.net/MATLABwww.math.utah.edu/lab/ms/matlab/matlab.htmlwww.utexas.edu/its/rc/tutorials/matlab/www.math.ufl.edu/help/matlab-tutorial/www.indiana.edu/~statmath/math/matlab/links.htmlwww-h.eng.cam.ac.uk/help/tpl/programs/matlab.html

24Intro MATLABReferencesMastering MATLAB 7, D. Hanselman and B. Littlefield,Prentice Hall, 2004

Getting Started with MATLAB 7: A Quick Introductionfor Scientists and Engineers, R. Pratap, Oxford University Press, 2005.25Basic Interfaces26Intro MATLABMain MATLAB Interface

27Intro MATLABSome MATLAB Development WindowsCommand Window: where you enter commandsCommand History: running history of commands which is preserved across MATLAB sessionsCurrent directory: Default is $matlabroot/workWorkspace: GUI for viewing, loading and saving MATLAB variablesArray Editor: GUI for viewing and/or modifying contents of MATLAB variables (openvar varname or double-click the arrays name in the Workspace)Editor/Debugger: text editor, debugger; editor works with file types in addition to .m (MATLAB m-files)28Intro MATLABMATLAB Editor Window

29Intro MATLABMATLAB Help Window (Very Powerful)

30Intro MATLABCommand-Line Help : List of MATLAB Topics>> helpHELP topics: matlab\general - General purpose commands.matlab\ops - Operators and special characters.matlab\lang - Programming language constructs.matlab\elmat - Elementary matrices and matrix manipulation.matlab\elfun - Elementary math functions.matlab\specfun - Specialized math functions.matlab\matfun - Matrix functions - numerical linear algebra.matlab\datafun - Data analysis and Fourier transforms.matlab\polyfun - Interpolation and polynomials.matlab\funfun - Function functions and ODE solvers.matlab\sparfun - Sparse matrices.matlab\scribe - Annotation and Plot Editing.matlab\graph2d - Two dimensional graphs.matlab\graph3d - Three dimensional graphs.matlab\specgraph - Specialized graphs.matlab\graphics - Handle Graphics.etc...31Command-Line Help : List of Topic Functions>> help matfun 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.32Intro MATLABCommand-Line Help : Function Help>> help det DET Determinant. DET(X) is the determinant of the square matrix X. Use COND instead of DET to test for matrix singularity. See also cond. Overloaded functions or methods (ones with the same name in other directories) help laurmat/det.m Reference page in Help browser doc det33Intro MATLABKeyword Search of Help Entries>> lookfor whonewton.m: % inputs: 'x' is the number whose square root we seektestNewton.m: % inputs: 'x' is the number whose square root we seekWHO List current variables.WHOS List current variables, long form. TIMESTWO S-function whose output is two times its input.

>> whos Name Size Bytes Class Attributes ans 1x1 8 double fid 1x1 8 double i 1x1 8 double 34Intro MATLABstartup.mCustomize MATLABs start-up behaviorCreate startup.m file and place in:

Windows: $matlabroot\workUNIX: directory where matlab command is issued

My startup.m file:

addpath e:\download\MatlabMPI\srcaddpath e:\download\MatlabMPI\examplesaddpath .\MatMPIformat short gformat compacteliminates extra blank lines in output35Variables (Arrays) and Operators36Intro MATLABVariable Basicsno declarations neededmixed data typessemi-colon suppresses output of the calculations result>> 16 + 24ans = 40

>> product = 16 * 23.24product = 371.84

>> product = 16 *555.24;>> productproduct = 8883.837Intro MATLABVariable Basicscomplex numbers (i or j) require no special handlingclear removes all variables;clear x y removes only x and ysave/load are used toretain/restore workspace variables>> clear>> product = 2 * 3^3;>> comp_sum = (2 + 3i) + (2 - 3i);>> show_i = i^2;>> save three_things>> clear>> load three_things>> whoYour variables are:comp_sum product show_i >> productproduct = 54>> show_ishow_i = -1 use home to clear screen and put cursor at the top of the screen38Intro MATLABMATLAB Data The basic data type used in MATLAB is the double precision array

No declarations needed: MATLAB automatically allocates required memory

Resize arrays dynamically

To reuse a variable name, simply use it in the left hand side of an assignment statement

MATLAB displays results in scientific notation Use File/Preferences and/or format function to change default short (5 digits), long (16 digits) format short g; format compact (my preference)39Intro MATLABVariables RevisitedVariable names are case sensitive and over-written when re-used

Basic variable class: Auto-Indexed ArrayAllows use of entire arrays (scalar, 1-D, 2-D, etc) as operandsVectorization: Always use array operands to get best performance (see next slide)

Terminology: scalar (1 x 1 array), vector (1 x N array), matrix (M x N array)

Special variables/functions: ans, pi, eps, inf, NaN, i, nargin, nargout, varargin, varargout, ...

Commands who (terse output) and whos (verbose output) show variables in Workspace40Intro MATLABVectorization Example*>> type slow.mtic;x=0.1;for k=1:199901 y(k)=besselj(3,x) +log(x); x=x+0.001;endtoc;>> slowElapsed time is 17.092999 seconds.

*times measured on this laptop>> type fast.mtic;x=0.1:0.001:200;y=besselj(3,x) + log(x);toc;>> fastElapsed time is 0.551970 seconds.

Roughly 31 times faster without use of for loop41Intro MATLABMatrices: Magic Squares

This matrix is called a magic squareInterestingly, Durer also dated this engraving by placing 15 and 14 side-by-side in the magic square.

42Intro MATLABDurers Matrix: Creation

durer1N2row = [16 3 2 13; 5 10 11 8]; durer3row = [9 6 7 12]; durer4row = [4 15 14 1]; durerBy4 = [durer1N2row;durer3row;durer4row]; durerBy4

durerBy4 =

16 3 2 13 5 10 11 8 9 6 7 12 4 15 14 143Intro MATLABEasier Way...durerBy4 = 16 3 2 13 5 10 11 8 9 6 7 12 4 15 14 1

durerBy4r2 = [16 3 2 13; 5 10 11 8; 9 6 7 12; 4 15 14 1]durerBy4r2 =

16 3 2 13 5 10 11 8 9 6 7 12 4 15 14 144Intro MATLABMultidimensional Arrays>> r = randn(2,3,4) % create a 3 dimensional array filled with normally distributed random numbersr(:,:,1) = -0.6918 1.2540 -1.4410 0.8580 -1.5937 0.5711r(:,:,2) = -0.3999 0.8156 1.2902 0.6900 0.7119 0.6686r(:,:,3) = 1.1908 -0.0198 -1.6041 -1.2025 -0.1567 0.2573r(:,:,4) = -1.0565 -0.8051 0.2193 1.4151 0.5287 -0.9219randn(2,3,4): 3 dimensions, filled with normally distributed random numbers% sign precedes comments, MATLAB ignores the rest of the line45Intro MATLABCharacter Strings>> hi = ' hello';>> class = 'MATLAB';>> hihi = hello>> classclass =MATLAB>> greetings = [hi class]greetings = helloMATLAB>> vgreetings = [hi;class]vgreetings = helloMATLABsemi-colon: join verticallyconcatenation with blank or with ,46Intro MATLABCharacter Strings as Arrays>> greetingsgreetings = helloMATLAB>> vgreetings = [hi;class]vgreetings = helloMATLAB>> hi = 'hello'hi =hello>> vgreetings = [hi;class]??? Error using ==> vertcatCAT arguments dimensions are not consistent.note deleted space atbeginning of word;results in error47Intro MATLAByo =HelloClass

>> ischar(yo)ans = 1

>> strcmp(yo,yo)ans = 1String Functionsreturns 1 if argument is a characterarray and 0 otherwisereturns 1 if string arguments are thesame and 0 otherwise; strcmpi ignores case48Intro MATLABSet FunctionsArrays are ordered sets:

>> a = [1 2 3 4 5]a = 1 2 3 4 5>> b = [3 4 5 6 7]b = 3 4 5 6 7

>> isequal(a,b)ans = 0>> ismember(a,b)ans = 0 0 1 1 1returns true (1) if arrays are the same size and have the same valuesreturns 1 where a is in b and 0 otherwise49Intro MATLAB>> durer = [16 3 2 13; 5 10 11 8; 9 6 7 12; 4 15 14 1]

durer = 16 3 2 13 5 10 11 8 9 6 7 12 4 15 14 1

>> % durer's matrix is "magic" in that all rows, columns,>> % and main diagonals sum to the same number>> column_sum = sum(durer) % MATLAB operates column-wise

column_sum = 34 34 34 34Matrix OperationsMATLAB also hasmagic(N) (N > 2)function50Intro MATLABTranspose Operator>> % to get the row sums, we'll use the transpose operator>> % (an apostrophe)

>> durer'ans = 16 5 9 4 3 10 6 15 2 11 7 14 13 8 12 1

>> row_sums = sum(durer')'row_sums = 34 34 34 3451Intro MATLABDiagonal Elements>> durerdurer = 16 3 2 13 5 10 11 8 9 6 7 12 4 15 14 1

>> diag(durer) % diag plucks out the diagonal elementsans = 16 10 7 1

>> sum(diag(durer))ans = 3452Intro MATLABThe Other Diagonal>> durerdurer = 16 3 2 13 5 10 11 8 9 6 7 12 4 15 14 1

>> fliplr(durer) % flip left-rightans = 13 2 3 16 8 11 10 5 12 7 6 9 1 14 15 4>> sum(diag(fliplr(durer)))ans = 3453Intro MATLABMatrix Subscripting>> durerdurer = 16 3 2 13 5 10 11 8 9 6 7 12 4 15 14 1

>> diag_sum = durer(1,1) + durer(2,2) + durer(3,3)diag_sum = 33>> durer(4,4) = pidurer = 16.0000 3.0000 2.0000 13.0000 5.0000 10.0000 11.0000 8.0000 9.0000 6.0000 7.0000 12.0000 4.0000 15.0000 14.0000 3.1416

>> durer(4,4) = 154Intro MATLABColon Operator (Vector Creation)>> 1:5 % use the colon operator to create row vectorsans = 1 2 3 4 5

>> 1:0.9:6 % you can vary the increment (0.9 in this case)ans = 1.0000 1.9000 2.8000 3.7000 4.6000 5.5000

The last element is always less than or equal to the upper limit55Intro MATLABColon Operator (Indexing)>> sum(durer(1:3,4)) % sums first three % elements of column 4ans = 33

>> sum(durer(:,end)) % a lone colon is ALL % elements, end is % the last elementans = 3456Intro MATLABThe Dot OperatorBy default and whenever possible MATLAB will perform true matrix operations (+ - *). The operands in every arithmetic expression are considered to be matrices.If, on the other hand, the user wants the scalar version of an operation a dot must be put in front of the operator, e.g., .*. Matrices can still be the operands but the mathematical calculations will be performed element-by-element.A comparison of matrix multiplication and scalar multiplication is shown on the next slide.57Intro MATLABDot Operator Example>> A = [1 5 6; 11 9 8; 2 34 78]A = 1 5 6 11 9 8 2 34 78>> B = [16 4 23; 8 123 86; 67 259 5]B = 16 4 23 8 123 86 67 259 558Intro MATLABDot Operator Example (cont.)>> C = A * B % normal matrix multiplyC = 458 2173 483 784 3223 1067 5530 24392 3360

>> CDOT = A .* B % element-by-elementCDOT = 16 20 138 88 1107 688 134 8806 390

59Intro MATLABTwo Division OperatorsRight divide (familiar version) a/bWhat happens: a is divided by bRight operand goes into left operandLeft divide a\bWhat happens: b is divided by aLeft operand goes into right operandBehavior depends on operands (scalar vs. matrix)

Both operators work with matrices (of course). More later on what is actually calculated Comparison of the use of / and \ on next slide60Intro MATLABUsing the Division Operators>> x = 53.0;>> y = 22.5;

>> x/y

ans = 2.3556

>> x\y

ans = 0.4245

>> (x/y)^(-1)

ans = 0.4245For matrix operands, A\B is the solution toAx = B obtained by Gaussian elimination.

Read Arithmetic Operators + - * / \ ^ in MATLAB Function Reference:Help Search for: division

61Intro MATLABEasy 2-D Graphics

>> x = [0: pi/100: pi]; % [start: increment: end]>> y = sin(x);>> plot(x,y), title('Simple Plot')62Intro MATLABAdding Another Curve

Line color, style, marker type, all within single quotes; type>> doc LineSpecfor all available line properties>> z = cos(x);>> plot(x,y,'g.',x,z,'b-.'),title('More complicated')63Intro MATLABLab 1Create a row vector called X whose elements are the integers 1 through 9.Create another row vector called Temp whose elements are:15.6 17.5 36.6 43.8 58.2 61.6 64.2 70.4 98.8These data are the result of an experiment on heat conduction through an iron bar. The array X contains positions on the bar where temperature measurements were made. The array Temp contains the corresponding temperatures.Make a 2-D plot with temperature on the y-axis and position on the x-axis.The data shown in your plot should lie along a straight line (according to physics) but dont because of measurement errors. Use the MATLAB polyfit function to fit the best line to the data (use >> hold on; for multiple plots in same figure). In other words use polyfit to determine the coefficients a and b of the equation T = ax + bLastly, we can calculate a parameter called chi-square (2) that is a measure of how well the data fits the line. Calculate chi-square by running the MATLAB command that does the following matrix multiplication: >> (Temp-b-a*X)*(Temp-b-a*X)'

64Intro MATLABLab 2Write a MATLAB command that will generate a column vector called theta. theta should have values from 2 to 2 in steps of /100.Generate a matrix F that contains values of the following functions in the columns indicated: Column 1: cos() Column 2: cos(2)(1 + sin(2) Column 3: e -0.1||Evaluate each of the above functions for the values in the theta vector from above.Plot each of the columns of F against theta. Overlay the three plots, using a different color for each.Create a new column vector called maxVect that contains the largest of the three functions above for each theta. Plot maxVect against theta.Create a column vector called maxIndex that has the column number of the maximum value in that row.65Programming 66Intro MATLABMATLAB m-file EditorTo start: click icon or enter edit command in Command Window, e.g., >> edit test.mScripts and FunctionsDecision Making/Loopingif/elseswitch for and whileRunning Operating System CommandsOutline

67Intro MATLAB

You can save and run the file/function/script in one step by clicking hereTip: semi-colons suppress printing, commas (and semi-colons) allow multiple commands on one line, and 3 dots () allow continuation of lines without execution

m-file Editor Window68Intro MATLABScripts and FunctionsScripts do not accept input arguments, nor do they produce output arguments. Scripts are simply MATLAB commands written into a file. They operate on the existing workspace. Functions accept input arguments and produce output variables. All internal variables are local to the function and commands operate on the function workspace.A file containing a script or function is called an m-fileIf duplicate functions (names) exist, the first in the search path (from path command) is executed.69Intro MATLABfunction [a b c] = myfun(x, y)b = x * y; a = 100; c = x.^2;

>> myfun(2,3) % called with zero outputsans = 100>> u = myfun(2,3) % called with one outputu = 100>> [u v w] = myfun(2,3) % called with all outputsu = 100v = 6w = 4Functions First ExampleWrite these two lines to a file myfun.m and save it on MATLABs pathAny return value which is not stored in an output variable is simply discarded70THE END