1 Advanced MATLAB programming Morris Law Jan 19, 2013.

Slides:



Advertisements
Similar presentations
Tutorial on Matlab and OpenCV Rui Ma TA of CMPT 414 May 14, 2013 Office hours: Fridays 11:00-12:00, CSIL TA Office 1 (ASB 9838)
Advertisements

MATLAB – A Computational Methods By Rohit Khokher Department of Computer Science, Sharda University, Greater Noida, India MATLAB – A Computational Methods.
Beginning Programming for Engineers
Intro to modeling April Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.
Fixed point iterations and solution of non-linear functions
259 Lecture 17 Working with Data in MATLAB. Overview  In this lecture, we’ll look at some commands that are useful for working with data!  fzero  sum,
Introduction to MATLAB The language of Technical Computing.
1 A L L A H. Command-Window Workspace & Directory Command- History The Matlab Command window - Finding your way around.
Automation and Drives SIMATIC HMI The Human Machine Interface for internal use only Scope of Presentation Dept. of Industrial Electronics and Control Eng.
Introduction to MATLAB for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations.
Differential Equations Math Review with Matlab: Finding Solutions to Differential Equations S. Awad, Ph.D. M. Corless, M.S.E.E. D. Cinpinski E.C.E. Department.
MATLAB Presented By: Nathalie Tacconi Presented By: Nathalie Tacconi Originally Prepared By: Sheridan Saint-Michel Originally Prepared By: Sheridan Saint-Michel.
By Hrishikesh Gadre Session II Department of Mechanical Engineering Louisiana State University Engineering Equation Solver Tutorials.
MATLAB Extras Week 16 – 5/12/09 Kate Musgrave
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.
Non-Linear Simultaneous Equations
Computational Tools for Image Processing Lecture 1, Jan 22nd, 2007 Part 2 (8:10-9:20pm) by Lexing Xie EE4830 Digital Image Processing
Digital Image Processing Lecture3: Introduction to MATLAB.
EPSII 59:006 Spring Topics Using TextPad If Statements Relational Operators Nested If Statements Else and Elseif Clauses Logical Functions For Loops.
Lecture 35 Numerical Analysis. Chapter 7 Ordinary Differential Equations.
MATLAB Lecture One Monday 4 July Matlab Melvyn Sim Department of Decision Sciences NUS Business School
MATLAB Tutorials Session I Introduction to MATLAB Rajeev Madazhy Dept of Mechanical Engineering LSU.
INTRODUCTION FOR PERL MONGERS MATLAB. Outline 1. Matlab, what is it good for 2. Matlab’s IDE & functions 3. A few words about Maple 4. What needs to be.
Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy
1 Tips for solving Project 1 Reactor SO 3 SO 2 +O 2.
A L I MAM M OHAMMAD B IN S AUD I SLAMIC U NIVERSITY C OLLEGE OF S CIENCES D EPARTMENT OF M ATHEMATICS MATLAB 251 : MATH SOFTWARE Introduction to MATLAB.
Hydroinformatics: Session4 Dr Ivan Stoianov Room 328B Dr Andrew Ireson (Room 304) Mr Juan Rodriguez-Sanchez (411A) Mr Baback.
EECE 360/460 Matlab Tutorial Jan Outline What is Matlab? What is Matlab? Matlab Interface Matlab Interface Basic Syntax Basic Syntax Plotting Graphs.
Do Now: Factor x2 – 196 4x2 + 38x x2 – 36 (x + 14)(x – 14)
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (1): Introduction.
Numerical Computation Lecture 2: Introduction to Matlab Programming United International College.
System Control Theory Lab
Introduction to Matlab’s Graphical User Interface (GUI) Type “guide” “Guide” creates interface on a Figure window and code in an M-file. Some hidden code.
ECEN/MAE 3723 – Systems I MATLAB Lecture 2. Lecture Overview What is Simulink? How to use Simulink  Getting Start with Simulink  Building a model Example.
CS112 Scientific Computation Department of Computer Science Wellesley College Numb3rs Number and image types.
Numerical Methods for Solving ODEs Euler Method. Ordinary Differential Equations  A differential equation is an equation in which includes derivatives.
Introduction MATLAB stands for MATrix LABoratory.  Basics  Matrix Manipulations  MATLAB Programming  Graphics  Image types  Image Processing  Useful.
Scientific Computing General Least Squares. Polynomial Least Squares Polynomial Least Squares: We assume that the class of functions is the class of all.
OUTLINE Overview Numbers, variables and similar in Matlab
Mathematical Applications using MATLAB (Cont….)
BOĞAZİÇİ UNIVERSITY DEPARTMENT OF MANAGEMENT INFORMATION SYSTEMS MATLAB AS A DATA MINING ENVIRONMENT.
SIMULINK-Tutorial 1 Class ECES-304 Presented by : Shubham Bhat.
Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VII Introduction to SIMULINK Rajeev Madazhy
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
EE3417 – Introduction to Simulink
Recap Cubic Spline Interpolation Multidimensional Interpolation Curve Fitting Linear Regression Polynomial Regression The Polyval Function The Interactive.
Intro to Simulink April 15, Copyright , Andy Packard. This work is licensed under the Creative Commons.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 4 Chapter 15 General Least Squares and Non- Linear.
Simulink by Dr. Amin Danial Asham. References  MATLAB Help  Telemark University College - Department of Electrical Engineering, Information Technology.
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Tutorial 2 : Matlab - Getting Started.
Intro to Simulink Modified by Gary Balas 20 Feb 2011 Copyright , Andy Packard. This work is licensed under.
MATLAB and SimulinkLecture 61 To days Outline Graphical User Interface (GUI) Exercise on this days topics.
Signals in Matlab Matlab as a name stands for Matrix Laboratory.
ECEN/MAE 3723 – Systems I MATLAB Lecture 2.
Welcome to MATLAB.
Introduction to Matlab ( Google Search )
Other Kinds of Arrays Chapter 11
PreOpenSeesPost: a Generic Interface for OpenSees
Outline Matlab tutorial How to start and exit Matlab Matlab basics.
MATLAB DENC 2533 ECADD LAB 9.
Introduction to Neural Network toolbox in Matlab
Tutorial 2 SEG7550 Introduction to MATLAB II
Digital Image Processing
MATHEMATICAL MODELING
Demo of Basic Matlab Features
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.
MATLAB stands for MATrix LABoratory.
Introduction To MATLAB
1Peyton Spencer, 2Yang Liu, 2Dr. Kai Sun
Presentation transcript:

1 Advanced MATLAB programming Morris Law Jan 19, 2013

2 Outline Advance programming in MATLAB Error analysis using Hilbert matrix Solving non-linear equations Function approximation using Taylor's expansion Solving ordinary differential equations MATLAB toolboxes Simulink Image processing MATLAB GUI MATLAB for fun

3 Error analysis using Hilbert matrix Hilbert matrix is an NxN matrix with element (1/i+j-1). It is a typical example of ill conditioned matrix. hilb(5) in MATLAB will give 5x5 Hilbert matrix

4 Error analysis using Hilbert matrix Try the following MATLAB code (hilbtest.m) n = 5; H = hilb(n); x = [1:n]’; b = H * x; xx = H \ b ; error = x – xx condH = cond(H) Change n to 10, 15, 20 to test the error

5 Solving non-linear equations The following non-linear equations are considered. Above equations are stored in testfun.m. Consider one equation for each test.

6 Solving non-linear equations You may write your own solver using bisection method. Refer to nonlineq.m Or you may solve it simply for matlab function fzero. Refer to solvefun.m in the following function x0 = solvefunc % solve nonlinear function x = [-5:0.02:5]; y = testfun(x); hold on; plot(x,y); plot(x,zeros(size(x)),'r'); hold off x0=fzero('testfun',1); % solve with initial guess 1

7 Function approximations using Taylor ’ s expansion sin(x) can be approximated by expanding in Taylor series with f(x)=sin(x) at a=0 The Taylor series of f(x)

8 Function approximations using Taylor ’ s expansion The MATLAB code for sinappx.m can be written as, %approximate sin by taylor polynomial function y=sinappx(x) term=x; y=term; x2=x*x; n=1; %initialization while abs(term)>eps %have we summed enough yet? term=-term*x2/((n+1)*(n+2)); %update term y=y+term; %update sum n=n+2; %update n end Similarly you can modify the above to write cosappx.m

9 Solving ordinary differential equations Ordinary differential equation can be solved in MATLAB using functions like ode23 or ode45. For first order ODE, simply prepare a function y’ = f(x) and name it as yprime.m, then solve by tspan,y0) Plot the graph to show the solution. For higher order ODE, rewrite it into a system of first order ODE and solve similarly.

10 Solving ordinary differential equations To solve y’ - y – t = 0, the matlab code yprime.m should be like, function yp = yprime(y,t) yp = y + t; Solve it by tspan=[0,10]; y0 = 0; [t,y] = Plot the graph t vs y to show the solution plot(t,y)

11 Solving ordinary differential equations Another example to solve a 2 nd order ODE, y'' + y' + y + t = 0, the matlab code yprime1.m should be like, function yp=yprime1(y,t) yp(1) = y(2); yp(2) = -y(2) - y(1) -t; Solve it by tspan=[0,10]; y0 = 0; [t,y] = Plot the graph t vs the first and second column of y to show the solution y and y’ plot(t,y(*,1),y(*,2)) Refer to forfun/orbit.m to solve an orbit trajectory using ode23.

12 MATLAB Toolboxes Toolboxes add more functions and feature into MATLAB. You may also write own toolboxes. OEE501 has another MATLAB classroom license with the following toolboxes, Simulink Control System Toolbox Image Processing Toolbox Signal Processing Toolbox Simulink control design Toolbox Statistics Toolbox Science Faculty has subscribed the following toolboxes, Simulink Control System Toolbox Image Processing Toolbox MATLAB Compiler Neural Network Toolbox Optimization Toolbox Partial Differential Equation Toolbox Signal Processing Toolbox Simulink Control Design Spline Toolbox Statistics Toolbox Symbolic Math Toolbox System Identification Toolbox Wavelet Toolbox

13 Simulink Toolbox Provide a simulation environment for common discrete/continuous system Invoke by typing ‘simulink’ in command windows

14 Image Processing Toolbox Functions specialised for image processing such as imread, imshow, imadjust, imhist, histeq, …… Support almost all image format input and output. RGB vs index vs BW images

15 Examples Counting grain from microscopic images % % Demo for functions in image processing toolbox % imgdemo.m % I=imread('rice.png'); %J=imread('demo.jpg'); %I=rgb2gray(J); imshow(I) background = imopen(I,strel('disk',15)); figure, surf(double(background(1:8:end,1:8:end))),zlim([0 255]); set(gca,'ydir','reverse'); I2 = I - background; imshow(I2) I3 = imadjust(I2); imshow(I3); level = graythresh(I3); bw = im2bw(I3,level); bw = bwareaopen(bw, 50); imshow(bw); cc = bwconncomp(bw, 4); grain = false(size(bw)); grain(cc.PixelIdxList{8}) = true; figure;imshow(grain)

16 MATLAB GUIDE Development Environment for Graphical User Interface Invoke with ‘guide’ in command window Plenty of user interface like button, textbox, scrollbar to develop screen interfaces. Callback functions can be written for each graphics object. Save and load the GUI as figures

17 MATLAB for fun Check machine constants machine.m Plot circle using parametric equation circle.m, drawpattern.m Plot graph by loading data from file dataplot.m, grid.plt tic-tac-toe game written in MATLAB play.m

18 Thank you! For enquiry: send to