Introduction to MATLAB Session 5 Simopekka Vänskä, THL 2010.

Slides:



Advertisements
Similar presentations
MATLAB – A Computational Methods By Rohit Khokher Department of Computer Science, Sharda University, Greater Noida, India MATLAB – A Computational Methods.
Advertisements

Lecture 5.
Matlab Graphics S. Awad, Ph.D. M. Corless, M.S.E.E. E.C.E. Department University of Michigan-Dearborn Introduction to Matlab: 2D Graphics.
MATLAB – What is it? Computing environment / programming language Tool for manipulating matrices Many applications, you just need to get some numbers in.
Chapter 11 Above: Principal contraction rates calculated from GPS velocities. Visualized using MATLAB.
Introduction to Matlab:
Fall 2006AE6382 Design Computing1 Three Dimensional Plotting Learning Objectives –Understand the anatomy of a 3D plot –Basics of constructing plots in.
MATLAB GRAPHICS 2-D.
Computer Science in Practice This course is an introduction to problems (and solutions) that arise in applied fields of computer science such as machine.
Computer Science in Practice This course is an introduction to problems (and solutions) that arise in applied fields of computer science such as machine.
[FX,FY,FZ,...] = GRADIENT(F,...) [FX,FY,FZ,…] is numerical gradient of matrix F Distance between grid points in X,Y,Z,… direction FX corresponds to dF/dx,
MATLAB Week 3 17 November Outline Graphics – Basic plotting – Editing plots from GUI – Editing plots from m-file – Advanced plotting commands.
SVD(Singular Value Decomposition) and Its Applications
EPSII 59:006 Spring Topics Using TextPad If Statements Relational Operators Nested If Statements Else and Elseif Clauses Logical Functions For Loops.
EPSII 59:006 Spring Outline Managing Your Session File Usage  Saving Workspace  Loading Data Files  Creating M-files More on Matrices Review.
 1999 BG Mobasseri1 8/29/2015 MATLAB GRAPHICS - PART II ADVANCED PLOTTING June 4, ‘99.
Chapter 5 Review: Plotting Introduction to MATLAB 7 Engineering 161.
6.837 Linear Algebra Review Patrick Nichols Thursday, September 18, 2003.
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
6.094 Introduction to programming in MATLAB
Introduction to MATLAB January 18, 2008 Steve Gu Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB,
CMPS 1371 Introduction to Computing for Engineers PLOTTING.
MATLAB Plotting With MATLAB 1. Two Dimensional Plots The xy plot is the most commonly used plot by engineers The independent variable is usually called.
Introduction to Matlab & Data Analysis
6.837 Linear Algebra Review Patrick Nichols Thursday, September 18, 2003.
A Brief Introduction to Matlab Laila Guessous Dept. of Mechanical Engineering Oakland University.
Introduction to MATLAB Session 3 Simopekka Vänskä, THL Department of Mathematics and Statistics University of Helsinki 2011.
MA/CS 3751 Fall 2002 Lecture 24. MA/CS 3752 ginput ginput is a Matlab function which takes one argument input: number of points to select in the image.
The Hong Kong Polytechnic University Industrial Centre 1 MatLAB Lesson 4 : Polynomial Edward Cheung Room W311g 2008.
MATLAB for Engineers, by Holly Moore. ISBN © 2007 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
Lecture 10 2D plotting & curve fitting Subplots Other 2-D Plots Other 2-D Plots Curve fitting © 2007 Daniel Valentine. All rights reserved. Published by.
Introduction to MATLAB Session 1 Simopekka Vänskä, THL 2010.
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.
1 DKT 211 Basic Communication Engineering LAB # 1A : (Lecture 1) Introduction to Matlab  Basic Features  Scientific features  Array Operations  Script.
Barak Shenhav Early Evolution Course 11 Feb 2001 MATLAB Visualization, Functions & Debugging.
Introduction to MATLAB Session 4 Simopekka Vänskä, THL 2010.
2D Routines in 3D. Outline Announcements –HW II--due Friday. 5PM HW1 & Cookie Grids & Meshes Representing f(x,y) Lines & Surfaces in 3D Survey.
Numerical Analysis 3D Plots. A numerical method is a technique for computing a numerical approximation of the solution to a mathematical problem.
Recap Chapter 5 “Plotting” Two Dimensional Plots Simple x-y Plots Titles, Labels and Grids Multiple Plots.
Recap Plots with More than one Line Plots of Complex Arrays Line, Color and Mark Style Axis Scaling and Annotating Plots Subplots Polar Plots Logarithmic.
Introduction to Linear Algebra Mark Goldman Emily Mackevicius.
Problems and solutions Session 2. Introduction to MATLAB - Solutions 2 Problems Write your solutions to m-files 1. Check how matrix A = a) [2 0; b) [2.
Introduction to MATLAB Session 2 Simopekka Vänskä, THL Department of Mathematics and Statistics University of Helsinki 2010.
3D Transformation A 3D point (x,y,z) – x,y, and z coordinates
1 Lecture 5 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
GRAPHICS AND VISUALISATION WITH MATLAB UNIVERSITY OF SHEFFIELD CiCS DEPARTMENT Deniz Savas & Mike Griffiths May 2015.
More Matlab Graphics and GUI Graphics subplots some useful commands 3D graphics GUI GUI controls The callback property Other essential properties.
MA/CS375 Fall MA/CS 375 Fall 2002 Lecture 5.
An Introduction to Programming in Matlab Emily Blumenthal
Beginning Programming for Engineers Animation. Special matrix functions >> clear >> ones(2,3) >> zeros(3,5) >> ones(2) >> zeros(3) >> eye(4) >> magic(4)
EEE 242 Computer Tools for Electrical Engineering
1-2 What is the Matlab environment? How can you create vectors ? What does the colon : operator do? How does the use of the built-in linspace function.
MAE 421 Matlab review Prof. Mark Glauser Created by: David Marr.
Lecture 17 More Plotting Chapter 12 Matrices. Outline from Chapter D Plotting 11.4 Surface Plots 11.5 Interacting with Plotted Data.
How to use MATLAB (using M-files) Double click this icon To start Matlab 6.5.
Session III Plotting in MATLAB Rajeev Madazhy Dept of Mechanical Engineering LSU MATLAB Tutorials.
Plotting ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
Advanced Plotting Techniques Chapter 11 Above: Principal contraction rates calculated from GPS velocities. Visualized using MATLAB.
Reading and Writing Image Files
John Federici NJIT Physics Department
MATLAB LABORATORY SESSION
ENEE222 Elements of Discrete Signal Analysis Lab 11 1.
Plotting Chapter 5.
3D-Graphs A 3D surface is defined as: z = f(x, y)
Lecture 25.
Ch3 Graphics Overview of Plotting Editing Plots
Lecture 25: Exploring data
Advanced Plotting Techniques
CSCI N317 Computation for Scientific Applications Unit 1 – 5 MATLAB
Presentation transcript:

Introduction to MATLAB Session 5 Simopekka Vänskä, THL 2010

Introduction to MATLAB - Session 5 Contents of this course Session 4 Function functions Session 5 Graphics 2 More linear algebra Starting homework Session 1 General Matrices M-files Session 2 Some matrix commands Logical expressions Graphics 1 Session 3 My functions + strings, cells Controlling program flow

Graphics dimensional graphs

Introduction to MATLAB - Session 5 Graphics dimensional plots The graphical library of MATLAB is large.  See >> help graph2d >> help graph3d >> help specgraph When representing your computations, use some time to think effective visualization techniques Besides the image itself, control the axis, labels, ticks, grids, etc.  Nothing too much, nothing missing.

Introduction to MATLAB - Session 5 Line plot extensions plot3 draws the line in 3D grid puts the grid mode on/off area(x,Y) fills the columns of Y and draws them one upon theorher  Practical when showing how some partition developes polar plots the line in the polar coordinates Try the following >> t = (0:.001:1)’; >> plot3(cos(10*t),sin(10*t),t) >> grid >> s = [sqrt(t), t, t.^2]; >> subplot(1,2,1) >> area(t,s); >> subplot(1,2,2) >> plot(t,cumsum(s’)) >> polar(2*pi*t,cos(4*pi*t))

Introduction to MATLAB - Session 5 Scalar functions on plane - meshgrid A scalar function on plane: z = f(x,y). Meshgrid is needed for drawing: If x and y are vectors, we need to create all pairs (x(i),y(j)). >> [X,Y] = meshgrid(x,y); Try the following: >> x = 0:.1:1; >> y = 0:.2:2; >> [X,Y] = meshgrid(x,y); >> X >> Y >> plot(X,Y,’o’) Remark X and Y are constant in different coordinates.

Introduction to MATLAB - Session 5 Scalar functions on plane Some commands contour draws the contour plot mesh and surf draw the surface of the function (unfilled and filled), surfc both surface and contours  shading interp clears the surface lines  colorbar displays the scale  view sets the view angle  colormap sets the color scale Image, imagesc for pixel plots Try the following >> x = -1:.01:1; >> y = x; >> [X,Y] = meshgrid(x,y); >> Z = X.^2 + Y.^3; >> contour(x,y,Z) >> contour(x,y,Z,20) >> mesh(x,y,Z) >> surf(x,y,Z) >> shading interp; >> colorbar >> view(2) >> view([0 -1 1]) >> colormap hot >> colormap default >> surfc(x,y,Z) >> imagesc(x,y,Z)

Introduction to MATLAB - Session 5 Vectorfields on plane or in 3D A vector field on plane: F = (f 1 (x,y),f 2 (x,y)) quiver(X,Y,U,V) draws an arrow (U(j),V(k)) to each grid point (X(j),Y(k)) Similarly quiver3 in 3D Try the following: >> x = -1:.1:1; >> y = x; >> [X,Y] = meshgrid(x,y); >> U = X; >> V = Y.^2; >> quiver(X,Y,U,V);

Introduction to MATLAB - Session 5 Some other plotting functions hist(X) makes a histogram of each column of X  Returns also the number of elements falling in the intervals. bar(X) draws the columns of X as vertical bars pie(x) draws the pie plot of vector x (normalized) fill(X,Y,C) fills the polygons defined by the columns of X and Y with color C isosurface(X,Y,Z,F,V) draws the isosurface F(X,Y,Z) = V Try the following >> hist(randn(10000,2),20); >> N = hist(randn(1000,3),20); >> bar(rand(2,4)) >> pie(1:4) >> fill([ ],[ ],’r’) >> x = -1:.1:1; >> [X,Y,Z] = meshgrid(x,x,x); >> FXYZ = X.^2+2*Y.^2 - 3*Z.^2; >> isosurface(X,Y,Z,FXYZ,1)

Introduction to MATLAB - Session 5 Changing general figure properties Figure and axes properties, and many others, can be changed: General principle: Set a handle to current figure/axes with gcf/gca (get current figure/axes) To see the properties, use get To change the property, use set For more, see Handle Graphics Properties of help clf for clearing the figure Try the following >> bar(rand(2,4)) >> h = gca; >> get(h) >> set(h,’XtickLabel’,{’a’,’bcd’}) >> set(h,’YTick’,[])

More linear algebra

Introduction to MATLAB - Session 5 Matrix decompositions We finish the course with matrix decompositions, or, with the most important one SVD (for other decompositions, see HELP): Every matrix A has the singular value decomposition A = U*S*V’ >> [U,S,V]=svd(A); where  U and V are unitary matrices (the columns define an orthonormal basis)  S is a diagonal matrix with positive and decreasing elements.  Statisticians, compare to the principal component analysis. Every matrix has a pseudoinverse pinv(A) pinv(A) = V*R*U’ where R is a diagonal matrix with R(j,j) = 1/S(j,j) for nonzero S(j,j) and zero otherwise.  x = pinv(A)*y is the best nonregularized solution for all linear equations Ax=y.

Problems Session 5

Introduction to MATLAB - Session 5 Problems Draw the contour plot of function F(x,y) = x 1.5 y 2 exp(-(x-2)-(y-0.5)) on [0,5]x[0,5] and its gradient field with quiver command in the same picture.  Use meshgrid to create the X,Y –grid.  Compute the derivative by hand or by using your earlier differf.m function. Make a histogram of points randn(10000,1).

Homeworks

Introduction to MATLAB - Session 5 How to do your homework You can co-operate with other students  …but do not just copy the code. Add graphics (into the code) which demonstrates the calculations. How to return:  Write a m-file called runthis.m which calls your functions.  Put the m-files and data files in the same directory, and make sure that runthis.m file works.  Send all homework files to the lecturer, who will copy your program files to one directory and test it by executing runthis – command. If the program works well enough, you pass the homework. Lecturer contacts you by .

Introduction to MATLAB - Session 5 Homework Topics Personal finance – how your savings accumulate SIR – model for measles Homeworks are described in more details in pdf-files that are located at the course website.  If you find them very easy, do both. But return only one.

>> I hope you …have learned some MATLAB. And wish you a successful career with computational math!