Al-Amer 20061 An Introduction to MATLAB Lesson 2: M-files Dr. Samir Al-Amer Term 061.

Slides:



Advertisements
Similar presentations
Lecture 5.
Advertisements

Introduction to Graphing Using MATLAB. Line Graphs  Useful for graphing functions  Useful for displaying data trends over time  Useful for showing.
1 Chapter 4 Curve Plotting with MATLAB MATLAB provides some very powerful features for plotting and labeling curves. These operations can be performed.
Introduction to MATLAB for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 19P. 1Winter Quarter MATLAB: Script and.
ECEN/MAE 3723 – Systems I MATLAB Lecture 1. Lecture Overview  Introduction and History  Matlab architecture  Operation basics  Visualization  Programming.
MATLAB’s extensive, device-independent plotting capabilities are one of its most powerful features. They make it very easy to plot any data at any time.
Scripts and Flow Control. Scripts So far we have been entering commands directly into the command line But there is a better way Script files (and functions)
Functions.
MATLAB ME1107 Y Yan Reference: MATLAB for Engineers by Holly Moore (Pearson Prentice Hall)
Using Excel for Data Analysis in CHM 161 Monique Wilhelm.
Exam #3 Review: Comprehensive Exam Class 14.2 Palm Matlab Book Ch. 1-5.
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.
Al-Amer An Introduction to MATLAB Dr. Samir Al-Amer Term 062.
Introduction to MATLAB MECH 300H Spring Starting of MATLAB.
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.
Designing Effective Graphics Using MATLAB The Cain Project in Engineering and Professional Communication ENGINEERING SERIES.
Lecture 1: Introduction Lecture series based on the text: Essential MATLAB for Engineers and Scientists By Hahn & Valentine
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
Launch SpecE8 and React from GSS. You can use the chemical analyses in a GSS data sheet to set up and run SpecE8 and React calculations. Analysis → Launch…
Introduction to Engineering MATLAB – 6 Script Files - 1 Agenda Script files.
Plotting in MATLAB Rachel Davies Brittany Earnest Greg Fannon Nicholas Millan Khurram Najeeb.
INTRODUCTION TO MATLAB LAB# 01
Numerical Computation Lecture 2: Introduction to Matlab Programming United International College.
Chapter 1: Getting Started with MATLAB MATLAB for Scientist and Engineers Using Symbolic Toolbox.
What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation tools. Others include Maple Mathematica MathCad.
Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2010.
Introduction to Engineering MATLAB – 2 Introduction to MATLAB - 2 Agenda Defining Variables MATLAB Windows.
MATLAB Harri Saarnisaari, Part of Simulations and Tools for Telecommunication Course.
MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
Recap Sum and Product Functions Matrix Size Function Variance and Standard Deviation Random Numbers Complex Numbers.
Scientific Computing Introduction to Matlab Programming.
Matlab 14.html Cost: $100 Available in labs on Windows and Unix machines.
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
Chapter 6 Review: User Defined Functions Introduction to MATLAB 7 Engineering 161.
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
Introduction to MATLAB 7 MATLAB Programming for Engineer Hassan Migdadi Spring 2013.
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
Sept. 26, 2005 Lecture 6 - By Paul Lin 1 CPET 190 Lecture 6 Problem Solving with MATLAB
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
ENG 1181 First-Year Engineering Program College of Engineering Engineering Education Innovation Center First-Year Engineering Program MAT - Introduction.
Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2012.
Finding zeros (also called roots) of a function Overview: Define the problem Methods of solution Graphical Newton’s Bisection Secant.
1 Lecture 5 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
M ATLAB – What Is It ? Name is from matrix laboratory Powerful tool for – Computation and visualization of engineering and science mathematics – Communication.
Recap Functions with No input OR No output Determining The Number of Input and Output Arguments Local Variables Global Variables Creating ToolBox of Functions.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
Chapter 4 MATLAB Programming MATLAB Troubleshooting Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
MATLAB ® for Engineers, Holly Moore Fourth Edition, Global Edition © Pearson Education Limited 2015 All rights reserved. Figure 5.1 Simple Plot of Time.
Introduction to Programming on MATLAB Ecological Modeling Course Sep 11th, 2006.
MAE 421 Matlab review Prof. Mark Glauser Created by: David Marr.
How to use MATLAB (using M-files) Double click this icon To start Matlab 6.5.
M ATLAB – What Is It ? Name is from matrix laboratory Powerful tool for – Computation and visualization of engineering and science mathematics – Communication.
Prof. Mark Glauser Created by: David Marr
Computer Application in Engineering Design
Appendix B MathScript Basics
Basic operations in Matlab
Lecture 1: Introduction
MATLAB How to use (using M-files) Double click this icon
MATLAB – What Is It ? Name is from matrix laboratory Powerful tool for
MATLAB – What Is It ? Name is from matrix laboratory Powerful tool for
MATLAB How to use (using M-files) Double click this icon
MATLAB – What Is It ? Name is from matrix laboratory Powerful tool for
MATLAB How to use (using M-files)
Introduction to MATLAB Programming
Designing Effective Graphics Using MATLAB
Presentation transcript:

Al-Amer An Introduction to MATLAB Lesson 2: M-files Dr. Samir Al-Amer Term 061

Al-Amer Objectives To be able to create MATLAB m-files To understands the basics of MATLAB files Basic graphics

Al-Amer Creating M-files Select FILE  OPEN  NEW  M-files

Al-Amer MATLAB shortcuts Open an existing files Create a New file

Al-Amer Programming in MATLAB There are two types of MATLAB programs % script file P=[1 3 2] roots(P) function [y]=fun(x) y=x^2+3*x^2+2 script files function files

Al-Amer Script verses functions files Script files List of MATLAB statements Variables are global Run it by typing the file name Function files Starts with function List of MATLAB statements Variables are local

Al-Amer Programming in MATLAB Script files Use script file when you have a long sequence of statements to solve a problem Run the program by typing its name in the command window from tools in the editor window

Al-Amer Example 1 Write a function file to compute the factorial of a number. Input: N Output :NF Function name: factorial

Al-Amer A solution function [FC]=factorial(N) FC=1; for i=1:N FC=FC*i; end outputFunction nameinput Save the program using ‘factorial’ as a name First statement must start with ‘function’

Al-Amer Creating function file function [FC]=factorial(N) FC=1; for i=1:N FC=FC*i; end Save the program using ‘factorial’ as a name If NOTEPAD is used to create the file use the name ‘factorial.m’ Save it in directory recognized by MATLAB If the directory is not recognized by MATLAB add it to the MATLAB path Open an m-file and start typing the file

Al-Amer A Better one function [FC]=factorial(N) % [FC]=factorial(N) % program to calculate the factorial of a number % input N : an integer % if N is not an integer the program obtains the % factorial of the integer part of N % output FC : the factorial of N % FC=1; % initial value of FC for i=1:N FC=FC*i; % n! =(n-1)!*n end These comments will be displayed when ‘help factorial’ is typed Comments are used to explain MATLAB statements

Al-Amer Script file to compute factorial % program to calculate the factorial of a number % input N : an integer % if N is not an integer the program obtains the % factorial of the integer part of N % output FC : the factorial of N % FC=1; % initial value of FC for i=1:N FC=FC*i; % n! =(n-1)!*n end Comments are used to explain MATLAB statements

Al-Amer Script file to compute cos % program to calculate an estimate of cos(0.2) % cos(x) ≈1-x^2/2!+x^4/4! x=0.2 Sum=1 N=2 fact2 Sum=Sum-x^2/FC N=4 fact2 Sum=Sum+x^4/FC Script file

Al-Amer Graphics on MATLAB Simple 1D graphics Linear scales Semilog scale Loglog scale 2D graphics

Al-Amer Example time=[0:0.01:6] Y=sin(time) plot(time,Y) xlabel('time') ylabel('sin(time) ') title(' plot of sin(time) ') grid Generating data Plot Y verses time x- axis is time y- axis is Y Add a label to the x- axis Add a label to the y- axis Add a title Add grid lines

Al-Amer

Al-Amer Example time=[0:0.01:6] Y=sin(time) plot(time,Y) Generating data Plot Y verses time x- axis is time y- axis is Y You can add a label to the x- axis Title And others on the graph directly (click insert)

Al-Amer Example time=[0:0.01:6] Y=sin(time) plot(Y) Generating data Plot Y verses index x- axis is column # y- axis is Y

Al-Amer Example time=[0:0.01:6] Y=sin(time) semilogx(time,Y) Generating data Plot Y verses time x- axis is time (log scale) y- axis is Y (linear scale) semilogy(t,Y) Plot Y verses v x- axis is v (linear scale) y- axis is Y (log scale) loglog(t,Y) Plot Y verses v x- axis is v (log scale) y- axis is Y (log scale) You can modify the scales directly on the figure Click Edit-  axis properties