Today we will learn MATLAB Click Start  All programm  Class Software  Matlab This command window will be seen with a prompt sign >> Any command can.

Slides:



Advertisements
Similar presentations
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 10.
Advertisements

Introduction to Graphing Using MATLAB. Line Graphs  Useful for graphing functions  Useful for displaying data trends over time  Useful for showing.
MATLAB – What is it? Computing environment / programming language Tool for manipulating matrices Many applications, you just need to get some numbers in.
Exponential Functions Logarithmic Functions
Flow Charts, Loop Structures
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
Introduction to MATLAB 7 for Engineers
Dr. Jie Zou PHY Welcome to PHY 3320 Computational Methods in Physics and Engineering.
Lecture 2 MATLAB fundamentals Variables, Naming Rules, Arrays (numbers, scalars, vectors, matrices), Arithmetical Operations, Defining and manipulating.
Programming in Matlab Day 1: Basics. Matlab as a calculator >> 2+2 ans = 4 >> 2^3 ans = 8 >> sqrt(2) ans = Command Window Basic operations Sum:
Matrix Mathematics in MATLAB and Excel
The TI-83 Calculator Bruce Thomas Mathematics Department Kennesaw State University
Introduction to MATLAB ENGR 1187 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
Programming For Nuclear Engineers Lecture 12 MATLAB (3) 1.
Chapter 4 MATLAB Programming Combining Loops and Logic Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Mathcad Variable Names A string of characters (including numbers and some “special” characters (e.g. #, %, _, and a few more) Cannot start with a number.
Chapter 10 Review: Matrix Algebra
Creating scalars, vectors, matrices Ex1 & 2. Dot Product & Cross Product Ex3. Plotting Graphs Ex4. Conversion Table Ex5. Plotting functions Finishing Ex4.
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
MATLAB Tutorials Session I Introduction to MATLAB Rajeev Madazhy Dept of Mechanical Engineering LSU.
1 Chapter 1 MATLAB Primer This introductory chapter is relatively short and has as its main objective the introduction of MATLAB ® to the reader. This.
Lecture 4 MATLAB Windows Arithmetic Operators Maintenance Functions
1 Tips for solving Project 1 Reactor SO 3 SO 2 +O 2.
Math 15 Lecture 7 University of California, Merced Scilab A “Very” Short Introduction.
Excel Simple Computation. Compute the Mean Place the cursor over a cell, click, and type. Pressing the enter key moves to the next cell. Here I typed.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
MEGN 536 – Computational Biomechanics MATLAB: Getting Started Prof. Anthony J. Petrella Computational Biomechanics Group.
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
ENG 1181 College of Engineering Engineering Education Innovation Center MATLAB is a powerful program for numerical computations, plotting and programming.
Introduction to MATLAB ENGR 1181 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
Introduction to Engineering MATLAB – 1 Introduction to MATLAB Agenda Introduction Arithmetic Operations MATLAB Windows Command Window Defining Variables.
EECE 360/460 Matlab Tutorial Jan Outline What is Matlab? What is Matlab? Matlab Interface Matlab Interface Basic Syntax Basic Syntax Plotting Graphs.
CNG 140 C Programming Lecture Notes 2 Processing and Interactive Input Spring 2007.
A First Book of ANSI C Fourth Edition Chapter 3 Processing and Interactive Input.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
Numerical Computation Lecture 2: Introduction to Matlab Programming United International College.
Matlab Basics Tutorial. Vectors Let's start off by creating something simple, like a vector. Enter each element of the vector (separated by a space) between.
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.
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
Introduction to Engineering MATLAB – 2 Introduction to MATLAB - 2 Agenda Defining Variables MATLAB Windows.
CMPS 1371 Introduction to Computing for Engineers MatLab.
10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.
Scientific Computing Introduction to Matlab Programming.
Introduction to MATLAB ENGR 1181 MATLAB 1. Opening MATLAB  Students, please open MATLAB now.  CLICK on the shortcut icon → Alternatively, select… start/All.
INTRODUCTION TO MATLAB MATLAB is a software package for computation in engineering, science, and applied mathemat-ics. It offers a powerful programming.
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
(The Transpose Operator) 1 >> C=[ ; ; ] C = >> D=C' D =
Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.
ENG 1181 First-Year Engineering Program College of Engineering Engineering Education Innovation Center First-Year Engineering Program MAT - Introduction.
Polynomials, Curve Fitting and Interpolation. In this chapter will study Polynomials – functions of a special form that arise often in science and engineering.
INTRODUCTION TO MATLAB DAVID COOPER SUMMER Course Layout SundayMondayTuesdayWednesdayThursdayFridaySaturday 67 Intro 89 Scripts 1011 Work
INTRODUCTION TO MATLAB Dr. Hugh Blanton ENTC 4347.
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
MA/CS 375 Fall 2002 Lecture 2. Motivation for Suffering All This Math and Stuff Try the Actor demo from
CMPS 1371 Introduction to Computing for Engineers VECTORS.
1 Faculty Name Prof. A. A. Saati. 2 MATLAB Fundamentals 3 1.Reading home works ( Applied Numerical Methods )  CHAPTER 2: MATLAB Fundamentals (p.24)
Manipulating MATLAB Vector, Matrices 1. Variables and Arrays What are variables? You name the variables (as the programmer) and assign them numerical.
CS100A, Fall 1998, Lecture 191 CS100A, Fall 1998 Lecture 19, Thursday Nov 05 Matlab Concepts: Matlab arrays Matlab subscripting Matlab plotting.
1 Structured Programming EEN170 Programming in MATLAB.
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
LAB 2 Vectors and Matrices Dr.Abdel Fattah FARES.
ECE 1304 Introduction to Electrical and Computer Engineering
ECE 1304 Introduction to Electrical and Computer Engineering
INTRODUCTION TO BASIC MATLAB
MATLAB DENC 2533 ECADD LAB 9.
A First Book of ANSI C Fourth Edition
Communication and Coding Theory Lab(CS491)
Introduction to MATLAB
Matlab Basics Tutorial
Presentation transcript:

Today we will learn MATLAB Click Start  All programm  Class Software  Matlab This command window will be seen with a prompt sign >> Any command can be written after the prompt sign. First let us play with matlab and see how it works when you enter a command!!

Type: >> and hit the return key. See the answer? Now type >> a = and hit the return key. The variable a now is assigned the value 2. Type >> a and hit the return key. Now type >> b = 2 + 1; and hit the return key. Semi-colon suppresses display of the output (later, you’ll see how helpful that is in case the output is a huge array of numbers). Computer now remembers what b is. Type >> b and hit the return key. See the answer? Now type >> clear and hit the return key. This wipes out computer memory, which is useful once in a while. Now type >> b and see the error message. (These error messages are very useful.)

Arithmetic Operations :. The operations + and - are as usual addition and subtraction. Try >> 2 -3 Operation * is multiplication. Try >> 3*2 Operation / is division. Try >> 3/2 a to the power b is a^ b. Try >> 3^(-2) To make sure that operations are done in proper sequence, use brackets. For example, >> 3/2+1 means, while >> 3/(2+1) means.

Type „clc“ to clear the page.Note „clc“ is not same as „clear“

for-end Loop If you want to compute the sum the easiest way to do it is: >> Sum = 0; for j = 1:10 Sum = Sum + 1/j; end Be careful to have spaces between commands. Computer would understand forj as a single unknown word.) Here, first, before summation starts, you define Sum to be equal to 0. Then, inside the loop, you add 1/j to “old” value of Sum to get “new” value Sum + 1/j, each time increasing Sum by 1/j, where j changes from 1 to 10. Obviously, this is much more economical than to type Note: >> 1 + 1/2 + 1/3 + 1/4 + 1/5 + 1/6 + 1/7 + 1/8 + 1/9 + 1/10 Type >>Sum

Use Upper cursor to type the last command; use it repeatedly to type the one before last, etc. Vector variables Row vector (same as row array) is a one-dimensional array of numbers. You can define a vector by specifying its elements, try, for example: >> x = [1,2,3,4,5] The same vector can be defined much more elegantly if you type: >> x = (1:5) If you want just to define a vector without displaying it on the screen, use semicolon (for instance, x = (1 : 5);) Imagine forgetting to put semicolon after command x = (1 : 5000) - try it!

Opoooos !!!! 

Very often you would want to define a linear array with constant small increment, for example, you want to introduce vector Elegant way to do it is to type: >> x = (1:0.1:1.5) If x is a vector, then command >> x(k) where k is any number from 1 to n, gives the number equal to the k th element of vector x. Try: >> x = (1:50); x(32) You have to be careful doing arithmetic operations with vectors. For example, if you want a vector, each element of which is a square of the corresponding element of vector x, you have to use the “dot” before the “power” command. Try (incorrectly): >> x=(1:4); y=x^2 Now try (correctly): >> x=(1:4); y=x.^2 Similarly, to multiply or divide elements of one vector by corresponding elements of another vector of the same length, use.* or./ respectively. For example, try:>> x=(1:4); y=(5:8); a=y.*x, b=y./x You can multiply or divide the vector by a number as usual; try >> x=(1:4); y=x/2, z=2*x

Special vectors: >> y=zeros(size(1:4)) or >> x=(1:4); y=zeros(size(x)) introduces the vector [ ] >> y=ones(size(1:4)) or >> x=(1:4); y=ones(size(x)) introduces the vector [ ] Mathematical functions: Sin(x); cos(x); exp(x) are Sin, Cos and exponential functions. log(x) is natural logarithm function with base e. abs(x) is absolute value of x. sign(x) is equal to +1 if x is positive, -1 if x is negative, and 0 if x = 0. sqrt(x) is square root of x.

Try: >> sin(pi/2) >> exp(1) >> log(exp(2)) >> abs(-2) >> sign(-2) >> sqrt(4)

Plots: To plot a graph function b(t), where both b and t are vectors of the same size, use command plot(t,b) Try >> t = (1:10); b = sin(t); plot(t,b) If you do not want the points on the graph to be connected by lines, try: >> t = (1:10); b = sin(t); plot(t,b,'*') To make a graph of different color (for example, red), try >> t = (1:10); b = sin(t); plot(t,b,'r*') Now, try: >> t = (1 :0.1:10); b = sin(t); plot(t,b) See the difference ?

>> t = (1 :0.1:10); b = sin(t); plot(t,b) >> t = (1:10); b = sin(t); plot(t,b,'r*')

If statement. Try to type- >> a = 1; if (a = = 2 || a > 3) b = 1; else b = 2; end Then type b. Here you first assigned value 1 to the variable a. Then, you told to computer that if either a is equal to 2, or a is more than 3, then the variable b is assigned value 1, otherwise b = 2. Then you checked that b = 2, indeed, because a = 1. More complicated if statement: c = 1; if c < -1 d = 1; else if c < 2 d = 2; else d = 3; end This is self-explanatory. (Note that there should be a space between else and if.) Type d and see what it equals to. Pay attention how semicolon and end are used.

If you have any doubt : You can use command >> help if you are in trouble or if you need to find out more. For example, try >> help plot

Now we can study a few models Logistic Growth Model: >> tend=20; r=0.1; t=(1:tend); x=0.5*ones(size(t)); >> for j=1:tend-1 if x(j)<1 x(j+1)=r*x(j)*(1-x(j)); else x(j+1)=0; end, end, plot(t,x) To simulate just type: r=0.1;x0=0.5

R=2.1 R=3.5 R=0.8 Just change the value of r, with x=0.5

Now try for for all r=0.1 to r=1 with increment 0.2 for r=.1:0.2:1 tend=100; t=(1:tend); x=0.5*ones(size(t)); for j=1:tend-1 if x(j)<1 x(j+1)=r*x(j)*(1-x(j)); else x(j+1)=0; end, end, plot(t,x),hold on end With hold on command we can plot for all values of r. Otherwise you can change r and see the graph. We have used a loop

What happens when 1 < r < 2 ? >> for r=1:0.2:2 tend=100; t=(1:tend); x=0.5*ones(size(t)); for j=1:tend-1 if x(j)<1 x(j+1)=r*x(j)*(1-x(j)); else x(j+1)=0; end, end, plot(t,x),hold on end

What happens when 2 < r < 3 ? >> for r=2:0.2:3 tend=100; t=(1:tend); x=0.5*ones(size(t)); for j=1:tend-1 if x(j)<1 x(j+1)=r*x(j)*(1-x(j)); else x(j+1)=0; end, end, plot(t,x),hold on end

What happens when 3< r < 4 ? X=0.5

r=3.95; x1(1)=0.3; x2(1)=0.33 r=3.4; x1(1)=0.3; x2(1)=0.33; Now try different initial conditions

Ricker Model of Fish population >> tend=50; r=1; h=0; t=(1:tend); x=0.5*ones(size(t)); >> for j=1:tend-1 x(j+1)=r*x(j)*exp(-x(j))-h; end, plot(t,x) The Ricker model is a classic discrete population model which gives the expected number x t+1 (or density) of individuals in generation t + 1 as a function of the number of individuals in the previous generation, x(j+1)=r*x(j)*exp(-x(j))-h; Type this to simulate

R=1 R=0.5 R=7 R=10 All the plot for h=0

R=14 R=20 R=30 All the plot for h=0

Now start Fishing: increase h from 0 to.15 tend=50; r=2; h=0; t=(1:tend); x=0.5*ones(size(t)); for j=1:tend-1 x(j+1)=r*x(j)*exp(-x(j))-h; if x(j+1)>0 x(j+1)=x(j+1); else x(j+1)=0; end, end, plot(t,x) r=2, h=0 r=2, h=0.15

r=7; h=1.6r=7; h=1.7 r=10; h=2.4r=10; h=2.0 Increase r and h

Different initial condition x=1.5 r=10; h=2 r=10; h=2.4 r=10; h=2.7 r=10; h=2.72

tend=100; h=0.1;r=20; t=(0:tend); x=2*ones(size(t)); for j=1:tend-1 x(j+1)=r*x(j)*(exp(-x(j)))-h; end plot(t,x) Here r=20, h=0.1 Even tiny harvest is ruinous if population in some years is fragile.

Smart strategy: skip dangerous years when population is low tend=100; h=2.6;r=10; t=(0:tend); x=1.65*ones(size(t)); for j=1:tend-1 if x(j+1)>0 x(j+1)=x(j+1); else x(j+1)=x(j+1)+h; end x(j+1)=r*x(j)*(exp(-x(j)))-h; end plot(t,x)

1)If electric potential, the heart did not recover ; it skips the beat and the potential does not change 2) If electric potential, the heart recovered; it beats and the potential increases: 3) Between consecutive signals, the potential decreases by the factor : Heart Model

> tend=20; c=0.3; t=(1:tend); x=0.5*ones(size(t)); >> for j=1:tend-1 if c*x(j)>1 x(j+1)=c*x(j); else x(j+1)=c*x(j)+1; end, end, plot(t,x) Type these 2 lines in command window to simulate: Which means, x increases if it is less than 1/c and decreases if it is more than 1/c

Now increase c from 0.3 till 1.1 with increment 0.1. C=0.3 C=0.4 C=0.5 C=0.6 Interpret the results for c=0.6 in words.

x increases if it is less than 1/c and decreases if it is more than 1/c Explanation of the result for c=0.6 1/c

C=0.7 C=0.8 C=0.9 C=1.0

C=1.1