EPSII 59:006 Spring 2004. Topics Using TextPad If Statements Relational Operators Nested If Statements Else and Elseif Clauses Logical Functions For Loops.

Slides:



Advertisements
Similar presentations
1 1 Mechanical Design and Production Dept, Faculty of Engineering, Zagazig University, Egypt. Mechanical Design and Production Dept, Faculty of Engineering,
Advertisements

Introduction to Programming using Matlab Session 2 P DuffourJan 2008.
Introduction to Matlab
Getting started with Simulink An introductory tutorial ES205 Analysis and Design of Engineering Systems Rose-Hulman Institute of Technology © R. Layton.
Programming with MATLAB
Chapter 8 and 9 Review: Logical Functions and Control Structures Introduction to MATLAB 7 Engineering 161.
By Hrishikesh Gadre Session II Department of Mechanical Engineering Louisiana State University Engineering Equation Solver Tutorials.
Introduction to MATLAB
1 A Tool for System Simulation: SIMULINK Can be used for simulation of various systems: – Linear, nonlinear; Input signals can be arbitrarily generated:
General Computer Science for Engineers CISC 106 Lecture 08 Dr. John Cavazos Computer and Information Sciences 2/27/2009.
SIMULINK Dr. Samir Al-Amer. SIMULINK SIMULINK is a power simulation program that comes with MATLAB Used to simulate wide range of dynamical systems To.
HossamTalaat - MATLAB Course - KSU - 21/1/24 1 IEEE Student Branch - College of Engineering - KSU Getting started with Simulink By Prof. Hossam Talaat.
Introduction to programming in MATLAB MATLAB can be thought of as an super-powerful graphing calculator Remember the TI-83 from calculus? With many more.
Digital Image Processing Lecture3: Introduction to MATLAB.
Programming For Nuclear Engineers Lecture 12 MATLAB (3) 1.
Chapter Seven Advanced Shell Programming. 2 Lesson A Developing a Fully Featured Program.
MATLAB and SimulinkLecture 11 To days Outline  Introduction  MATLAB Desktop  Basic Features  Branching Statements  Loops  Script file / Commando.
INTRO TO PROGRAMMING Chapter 2. M-files While commands can be entered directly to the command window, MATLAB also allows you to put commands in text files.
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
1 Tips for solving Project 1 Reactor SO 3 SO 2 +O 2.
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
How to think through your program [ principles of good program design ] Rachel Denison MATLAB for Cognitive Neuroscience ICN, 13 December 2007.
1 Functions 1 Parameter, 1 Return-Value 1. The problem 2. Recall the layout 3. Create the definition 4. "Flow" of data 5. Testing 6. Projects 1 and 2.
Matlab Programming, part 1 M-files It is generally more convenient to program in Matlab using m-files, ascii text files containing a set of Matlab commands.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
Control Theory Lab 4 Modeling of Physical-SİMULİNK.
What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation tools. Others include Maple Mathematica MathCad.
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
CMPS 1371 Introduction to Computing for Engineers CONDITIONAL STATEMENTS.
MAE 1202: AEROSPACE PRACTICUM An Introduction to MATLAB: Part 2 Mechanical and Aerospace Engineering Department Florida Institute of Technology Developed.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
OUTLINE Overview Numbers, variables and similar in Matlab
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
Introduction to Matlab Module #9 Page 1 Introduction to Matlab Module #9 – Simulink Topics 1.Simulink Textbook Reading Assignments Practice Problems.
Introduction to Matlab Module #4 Page 1 Introduction to Matlab Module #4 – Programming Topics 1.Programming Basics (fprintf, standard input) 2.Relational.
Chapter 4 Controlling Execution CSE Objectives Evaluate logical expressions –Boolean –Relational Change the flow of execution –Diagrams (e.g.,
Introduction to MATLAB for Engineers Third Edition William J. Palm III Chapter 10 Simulink PowerPoint to accompany Copyright © The McGraw-Hill Companies,
GUI development with Matlab: GUI Front Panel Components GUI development with Matlab: Other GUI Components 1 Other GUI components In this section, we will.
SIMULINK-Tutorial 1 Class ECES-304 Presented by : Shubham Bhat.
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
Matlab Programming for Engineers
Digital Image Processing Lecture 6: Introduction to M- function Programming.
EE3417 – Introduction to Simulink
Introduction to Matlab
Simulink Simulink is a graphical extension to MATLAB for modeling and simulation of systems. In Simulink, systems are drawn on screen as block diagrams.
INTRODUCTION TO SIMULINK by Yasmin Hanum Md Thayoob & Aidil Azwin Zainul Abidin.
Structured Programming II: If Statements By the end of this class you should be able to: implement branching in a program describe and use an “if” statement.
INTRODUCTION TO MATLAB Dr. Hugh Blanton ENTC 4347.
Digital Image Processing Introduction to MATLAB. Background on MATLAB (Definition) MATLAB is a high-performance language for technical computing. The.
1 Lecture 5 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Simulink  ? 1 Simulink  ( Simu lation and Link ) is an extension of Matlab Offers modeling, simulation, and analysis of dynamical systems; i.e., a system.
The Department of Engineering Science The University of Auckland Welcome to ENGGEN 131 Engineering Computation and Software Development Lecture 2 Debugging,
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Tutorial 2 : Matlab - Getting Started.
Chapter 4 MATLAB Programming MATLAB Troubleshooting Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
MATLAB and SimulinkLecture 61 To days Outline Graphical User Interface (GUI) Exercise on this days topics.
Introduction to Computer Programming using Fortran 77.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
Getting started with Simulink
Getting started with Simulink An introductory tutorial.
Computer Application in Engineering Design
Matlab Training Session 4: Control, Flow and Functions
ECEN/MAE 3723 – Systems I MATLAB Lecture 2.
Scripts & Functions Scripts and functions are contained in .m-files
MATLAB DENC 2533 ECADD LAB 9.
Conditional Statements
Use of Mathematics using Technology (Maltlab)
Getting Started With Simulink
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
Presentation transcript:

EPSII 59:006 Spring 2004

Topics Using TextPad If Statements Relational Operators Nested If Statements Else and Elseif Clauses Logical Functions For Loops While Loops User Functions

TextPad TextPad is a Convenient Tool in the CSS Windows Environment for Writing Code It Recognizes Syntax Error Automatically Can Save Files Corrected for the Unix Environment for Importing Check it out! (I know, it’s a little late)

Back to Matlab

If Statements if expression statements end Expression might be (B>1)  When B is a scalar greater than 1, the statements are executed  When B is an array, each element must be greater than 1 for the statements to be executed.

Relational Operators Relational Operator Interpretation <Less than <=Less than or equal to >Greater than >=Greater than or equal to ==Equal to ~=No equal to

Using Relational Operators Arrays are considered element by element and the result is an array of the same size with 1 for true and 0 for false A = [ 5 9 2], B = [6 8 3] A > B [0 1 0]

Logical Operators Matrices are again compared element by element, non-zero is true, zero is false For example, ~5 = 0 There is also an exclusive or operator: xor(first_matrix, second_matrix) Logical Operator Symbol Not~ And& Or|

Nested If Statements Just as in C, you can nest if statements  A = [1 2 3], B = [-1 0 1], C = zeros(1,3) if (A > B) if (A > 0) C = A + B end C = [0 2 4]

Else and Elseif Clauses What does this do? A = 3; if (A > 4) C = 4; elseif (A > 3) C = 3 else C = 0 end

Logical Functions any(x), returns 1 if any element is nonzero all(x), returns 1 if all elements are nonzero find(x), returns a vector of all nonzero elements isnan(x), returns 1 at any locations of NaN in a matrix finite(x), returns a matrix with 1’s for finite elements, zeros otherwise isempty(x), returns 1 for an empty matrix

For Loops Try to avoid using for loops in MATLAB programs, usually you can process information in a matrix arrangement for index = expression statements end If index is a scalar, executes once, if a vector, once for each element in the vector, if a matrix, once for each column (index will be set to the column vector) for k = 1:2:10 will execute 5 times with k = [ ]

While loops while expression statements end Executes as long as the expression is true

Scripts We already talked about.m files If you define the.m file this way, it is a function that takes arguments and returns a value function d = dist(x) % Comments here print out when you % type ‘help dist’ d = sqrt(x * x’)

Revisit our two tank example Considering two tank example again. If the tanks are initially at steady state and a step change in from 0.05 to 0.06 at t=200 seconds is introduced, how do the tank levels change with time. Plot the tanks level vs. time for both systems. What is the new steady state value?

Example Problem The liquid levels in tank1 and tank 2 are given by T=200 q 1 increases

Example Continued

Example First create the M-file ‘step_tank.m’ contains the differential equation  function hdot = tank_1(t,h)  hdot=0.0;a1=0.05;A1=1.0;  if t<200 q1=0.05;else q1=0.06;end  hdot=(q1-a1*sqrt(h))/A1;(Note hdot is used to represent the derivative of h)

Example Next create the M-file ‘example3.m’ contains the code to solve the problem,  t0=0.0;tf=1000;h0=0.0;  tf],h0);  plot(t,h)  xlabel('time,seconds')  ylabel ('Liquid level,m')  title('Figure(3):Liquid Level in a tank')  grid on Run example.m

Introduction to Simulink The other method MATLAB uses to numerical differentiate (integrate) is via SIMULINK. SIMULINK is a program for simulating dynamic systems. It has two phases of use: model definition and model analysis. Thus you need to first define your model and then use modeling analysis to understand the system’s dynamic behavior.

Introduction to Simulink SIMULINK has a new class of windows called block diagram windows. After a model is defined, it can be analyzed either using the SIMULINK menus or using MATLAB's command window (workspace).

Introduction to Simulink Defining the model is easiest if one visualizes the loop for calculating the output as an approximate integration solution for small time steps. Use drag and drop to connect ‘blocks’ that represent, constants, integrals, operations, inputs and outputs. Easy to connect with lines.

Introduction to Simulink Starting SIMULINK At the MATLAB prompt type simulink or click the simulink button on the tool bar to open the main block library. From the SIMULINK window select New from the File menu. This will open an empty window where you can construct your model. Open one or more libraries, and drag the appropriate blocks (model the above diagram) into the active window. Connect the blocks by drawing lines between then using the mouse. Open the blocks (by double-clicking) and change their internal parameters. Block parameters can be any legal MATLAB expression. Save and re-name the system by choosing Save As from the File menu.

Introduction to Simulink Run a simulation by selecting Start from the Simulation menu. While a simulation is running the Start item becomes Stop. Adjust the simulation parameters by selecting Parameters from the Simulation menu. You can monitor the behavior of the system with scope block or you can use to work place block to send data to the MATLAB workspace and perform MATLAB functions on the results.

Introduction to Simulink As an example consider a single tank in previous example, where the time rate of change of the liquid level changes according to or

Introduction to Simulink Visualize the simulation method using small time steps and approximating the integral so that

Introduction to Simulink The block diagram for Simulink might be selected as follows.

Introduction to Simulink We obtained this by dragging over the integrator block, constant blocks, function block, etc. and then connecting them so that they result in the approximate integral shown above. Note that although SIMULINK uses the Laplace transform symbol for integration (1/s), SIMULINK is actually only approximating the solution and, thus, the integrator can be used with non-linear problems (such as this one). (Maybe they think 1/s is more beautiful than the integral sign.)

Introduction to Simulink The progress of simulation can be viewed while the simulation is running, and the final results can be made available in the MATLAB workspace when a simulation is completed.

Printing in Simulink The best way to obtain a hard copy of the graph you have generated or to print the block diagram of your model is to use the print provided by MATLAB. It has the following synopsis: print [-ddevice ] [-options ] [ filename ] Using print alone with no arguments send the contents of the current figure window to the default printer. While print filename saves the current figure to the designated file.

Printing in Simulink The following devices are available: -dps PostScript for black and white printers -dpscPostScript for color printers -dps2Level 2 PostScript, these are smaller and render more quickly when printing). -dlaserjetHP LaserJet. The following print options are supported: -append Append the graph to file, rather than overwriting. -S Name of SIMULINK model window to print. -P Specify the printer to use(UNIX only)