3 views

Uploaded by varshasdm1987

Matlab lec 1

save

You are on page 1of 52

MATLAB is:

A high-level language and interactive environment for numerical computation, visualization, and

programming

MATLAB can:

Be used as a calculator, easily create scalars, vectors and arrays, be used as a programming

environment, make sophisticated plots, be used to create models that describe experimental

data, solve statistics and probability problems, solve systems of linear algebraic equations, solve

differential equations

**MATLAB is used for:
**

Finite element analysis, computational fluid dynamics, signal processing and communications,

image and video processing, control systems, test and measurement, etc.

MATLAB is used by:

More than a million engineers and scientists in industry and academia

**Chapter 1: An Overview of MATLAB
**

Chapter 1 Topics Covered:

• MATLAB Windows: Current Folder, Command, Workspace, Command History

**• Using MATLAB as a Calculator
**

• Mathematical Operators

• Clearing Windows

• Assignment Operator

**• Using MATLAB Script Files
**

• Creating/Saving/Editing/Executing Script Files

• Changing the Destination Folder

• Using the Editor Window

• Built-In Functions

• Search Documentation

• Order of Mathematical Precedence

• Creating Arrays and using them in Calculations

• Creating Plots with Arrays (Graphics Window)

• Creating Arrays Automatically

• Understanding Error Signals and Error Messages

• Publishing MATLAB Files

**Using MATLAB as a Calculator
**

Open MATLAB.

Workspace

Window

Current

Command

Folder

Window

Window

Command

History

Window

Mathematical Operators

Type the following commands into the Command Window to solve Problem 1.1(a):

**The output of the calculation appears in the Command Window.
**

The semi-colon (;) suppresses output to the Command Window.

The Workspace Window shows the names and values of the Variables.

The Command History Window shows the entered commands.

Previous commands can be accessed quickly by using the Up Arrow and Down Arrow. Try this!

Workspace Window

**Command Command History
**

Window Window

Clear the Command Window by typing clc (and hit enter) into the Command Window. .

.Remove all of the variables from the Workspace by typing the command clear in the Command Window.

the equals sign (=) is called the Assignment or Replacement Operator.In the previous example. . Type in the following session to demonstrate that the Assignment Operator is different than the equals sign in mathematics.

the caret symbol (^) denotes exponentiation.The second command line that was typed in is shown in the Command History Window below. “Replace variable x with the current contents of variable x raised to the second power.” Use MATLAB to solve Problem 1.” In the third command line. It states the following: “Replace variable x with the current contents of variable x plus 1.3(a) as shown below: .

.

Using MATLAB Script Files Another method of computation is to create a Script File. Use the Home/New Script tab to create a new Script File: . which is a way to store commands to be executed in the Command Window.

. Use the Editor in MATLAB to solve Problem 1.The new window that has appeared is called the Editor/Debugger.3(a) by typing the following.

Before saving. change the folder that MATLAB saves files to (the Destination Folder) by pushing the Browse for Folder button: .

Select the Desktop folder to be the Destination Folder. .

Spaces are not allowed. Numbers are allowed. as long as the number is not the first character. . MATLAB Script File names must start with a letter. and the only special character allowed is the underscore.Save the file using the Save button.

pressing the Run button will automatically save the Script File. Alternatively. . Press the green Run button to execute the Script file.The file appears in the Desktop folder as a *.m file. The Script File must be saved prior to execution.

Notice that the values shown in the Workspace Window have changed.The results of the calculation appear in the Command Window. .

a squiggly line appears where MATLAB thinks the error lies. Hover the cursor over the red line: EOL stands for End Of Line. Delete the last parenthesis in the equation. and a red line appears at the line that has the mistake. Notice that the square becomes red. .MATLAB will give you clues when you make a mistake in your equations. Also.

.Make the following change in the Script File and save the program using the Save Button under the Editor drop-down menu prior to running the program.

In the modified Script File. Create a new Script File using the New File Button on the Editor. as shown in the following session where Problem 1. Other built-in functions exist.16(a) is to be solved. the built-in variable pi was used. . MATLAB gives the new file the temporary name Untitled2.

.

Get in the habit of typing in the first two commands to clear the command window and to clear the variables stored in memory.16(a). Save it to the Desktop using the Save As drop-down menu: .Type in the following to calculate the equation given in Problem 1.

Try it! Press the Run button to execute the new Script File. .Notice that you can toggle back and forth between the two saved files by clicking on the names in the Editor Window.

.

To learn how to use the atan (arc tangent) command. use the Search Documentation window: .

The Order of Precedence is a very important concept for properly performing calculations. Using Order of Precedence principles. create a MATLAB script file to calculate Problem 1-15(a). .

.

.

MATLAB can perform calculations on Arrays with the same ease as it does with single numbers (Scalars). Create and run a new Script File for Problem 1.13: .

The syntax for an Array is Variable_name(Index_number) = Value The Index Number shows where the particular Value resides within the Array. Index Number = 1.The new variable x is an Array of six separate numbers that can be acted on as a single unit. Value = 0 Notice that the Workspace Window shows all of the Values of variable x: . Index numbers are integers starting with 1.

Calculate the new variable y (Array) using the following equation in terms of variable x: .

.

Plot the resulting y Array versus the x Array : .

The Graphics Window appears. showing the graph of y versus x: .

use it to create a new Array y2.Create a new Array x2. and plot y2 versus x2: .

and Step is the step size used to go between Start and Stop. arranged in one row and eleven columns: .The Array x2 is created using an automated system. The Workspace Window now shows the new x2 and y2 variables as: <1x11 double> This means that they each have eleven numbers. with syntax as follows: Variable_Name = Start : Step : Stop where Start and Stop are the initial and final values (Range).

.

Refine the plot by making the value for Step much smaller: .

.

What happens when you try to plot y2 versus x? Try it! .Notice that the number of values in x2 and y2 is now 1001.

.

Use the comment symbol (%) to comment out the offensive command line. Go to the Publish tab as shown: .

Change the Output File Format to PDF: .

Publish the file: .

The file gets saved to a folder on the Desktop: .

- Delft3D-QUICKPLOT User Manual CopyUploaded byhjd
- Intro Tom at LabUploaded bymagic1111
- ArrayUploaded byRajiv Ranjan Sinha
- algoritmo en guide-matlabUploaded bycamus191
- Jukebox Report on matlabUploaded byAbhineet Kumar
- MfLab KeynoteUploaded byjaspreetsingh1243
- JavaScript ArraysUploaded byVaibhav Kale
- Simulink Tutorial - By tUploaded bymitev
- 1.4794857Uploaded byravsree
- arraysUploaded byapi-284283149
- MatlabUploaded byalysonmicheaala
- Vb Script_Good OneUploaded byAmit Rathi
- 02_Arrays & StringsUploaded bymanika
- Arrays in C++Uploaded bynamachivayam_d
- Java Slide Ch. 8Uploaded byHaseeb Nawaz
- c++ chapter 3Uploaded byAhmed Hossam
- COMPUTER PROGRAMMING (TMK 3102) LECTURE NOTES 9Uploaded bymamat88
- Berger George Etal 2011Uploaded byMetar Yoseplin Hutauruk
- cantera17-vc7Uploaded bySiva Ramakrishna Valluri
- 01-Introduction_to_MATLAB.pptxUploaded byajuen_99
- Learn Go in Y MinutesUploaded byAbhishek Kumar
- ProfilPredko HelpUploaded byarkczest
- Matlab TutorialUploaded byBen Chan
- MatlabUploaded byravidadhich7
- ST_manual (1)Uploaded byBernard Scott
- matlab GAUploaded byMelani Adrian 洪美蘭
- Fundamental Concepts of Data Sturctures(Assign#1-Datalgo)Uploaded byB.c. Hernaez
- 1d-arraysUploaded byవిశ్వేష్ నాగమల్ల
- lab3_talk.pdfUploaded bysharkman2020
- MATLAB Tutorial 2013Uploaded byvinaysamm

- basics of radiation.pdfUploaded byvarshasdm1987
- External Forced External ConvectionUploaded byvarshasdm1987
- Behavorial Int QuUploaded byvarshasdm1987
- Draw StressUploaded byvarshasdm1987
- Mechanical Eng QuesnsUploaded byvarshasdm1987
- German GreetingsUploaded byvarshasdm1987
- 1.Forced External ConvectionUploaded byvarshasdm1987
- Basics of GERMAN for Kids 1Uploaded byvarshasdm1987
- ImpUploaded byvarshasdm1987
- Interview.docUploaded byvarshasdm1987
- 1. Poems for Kids in GERMANUploaded byvarshasdm1987
- int_queUploaded byvarshasdm1987
- FundamentalsUploaded byvarshasdm1987
- Basics of ATDUploaded byvarshasdm1987
- Interview QuestionsUploaded byvarshasdm1987
- 1.Zeroth law of TDUploaded byvarshasdm1987
- CncUploaded byvarshasdm1987
- Cnc-programing for RoboticsUploaded byvarshasdm1987
- mod1Uploaded byvarshasdm1987
- CRUploaded byvarshasdm1987
- CncUploaded byvarshasdm1987
- 2.First Law TDUploaded byvarshasdm1987
- Thermo ReviewUploaded byvarshasdm1987
- Heat transfr.pdfUploaded byvarshasdm1987
- Maths ReviewUploaded byvarshasdm1987
- 3.Work doneUploaded byvarshasdm1987
- Practice Ex Fluid MechanicsUploaded byvarshasdm1987
- First Law thermoUploaded byvarshasdm1987
- TD Basics by Prof WKUploaded byvarshasdm1987

- 5-Vapor Liquid Equilibrium._depriester ChartUploaded byOgenioja
- PROGRAMACION EN JULIA.pdfUploaded byCarlos Paitan Benito
- 134124247-Diagrama-de-Flujo-de-La-Industria-Molinera.docUploaded byMiri Jf
- Trabajo Final Hidrología AplicadaUploaded byandresordos
- aula de compressores.pptUploaded byFernando Michelon Marques
- El Método de la RigidezUploaded byisgre
- Motor Single Phasing Voltage UnbalanceUploaded byrian0201
- SAP RFCUploaded byShivi
- 3 Strategies for an IP Core Network Refresh _ TechZine _ Alcatel-LucentUploaded byjrashev
- Nwd HandoutUploaded byjjkomen
- Análisis Morfológico (Estructura del Lenguaje) 2013-1Uploaded byMonic Bravo Diaz
- Manual de Produccion CerdosUploaded byguadalupecatucor
- tasseled cap.pdfUploaded byDavid Lara
- PhD ThesisfgITBV in Construction Industry - Dec 2012 HardCover Final-06!06!2013Uploaded bygren900
- Mañalich - Normas Permisivas y Deberes de ToleranciaUploaded byLuigiRawls
- Mitutoyo Digimatic IndicatorUploaded byxbudzek
- Análisis morfológicoUploaded byAndrea Chaparro
- a28v17n2Uploaded bymerc0581
- Geo_Fund_2Uploaded byPaulo Luz
- CFDR Research Proposal MKalergisUploaded byMiguel Badel
- 1. Literature ReviewUploaded byMohammed Razwin K P
- Wago.acspl Marine Approved ControlsUploaded byPAUL
- Libro de Quimica.pdfUploaded byValeria Michelle
- Conversión de Binario a DecimalUploaded byCarlos García
- MerUploaded byRosmeri Delgado Guerrero
- Seis Sigma - MBA Gestão de ProjetosUploaded byUrsula Felippe
- ROBELIO RECUPERACION.docxUploaded byrobelio
- 19.1A loss by evaporationIIUploaded byAlex Tafur
- QUÍMICA ORGÁNICA Grupos funcionalesUploaded byHéctor Matías Vera Orellana
- Fonctions-usuellesUploaded byosefresistance