Problems and solutions Session 3. Introduction to MATLAB - Solutions 3 Problems 1. Write function Xn = mspolygon(X,x0,a) that scales the INPUT polygon.

Slides:



Advertisements
Similar presentations
-seminar 1 for digital signal processing
Advertisements

Introduction to Matlab
Welcome to MATLAB DigComm LAB
Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
Header, Specification, Body Input Parameter List Output Parameter List
1.3 ARRAYS, FILES, AND PLOTS + FOURIER SERIES BY MR. Q.
MATLAB Examples. CS 1112 MATLAB Examples Find the number of positive numbers in a vector x = input( 'Enter a vector: ' ); count = 0; for ii = 1:length(x),
MATLAB - Basics Centro de Informática Universidade Federal de Pernambuco Aprendizagem de Máquina – IN1102 Arley Ristar –
Slide deck by Dr. Greg Reese Miami University MATLAB An Introduction With Applications, 5 th Edition Dr. Amos Gilat The Ohio State University Chapter 3.
Final Project Part II MATLAB Session ES 156 Signals and Systems 2007 SEAS Prepared by Frank Tompkins.
Introduction to Matlab II EE 2303 Lab. Basic Matlab Review Data file input/output string, char, double, struct  Types of variables load, save  directory/workspace.
Lecture 6 MATLAB functions Basics of Built-in Functions, Help Feature, Elementary Functions (e.g., Polynomials, Trigonometric Functions), Data Analysis,
Lecture 4 Sept 8 Complete Chapter 3 exercises Chapter 4.
Matrices and arrays Pekar Miriam. What is matrices? In MATLAB environment, a matrix is a rectangular array of number Vector - 1 by 1 row/ column matrix.
Introduction to MATLAB Northeastern University: College of Computer and Information Science Co-op Preparation University (CPU) 10/27/2003.
GG250 F-2004 Lab 6-1 Components of Scientific Programming Definition of problem Physical/mathematical formulation Development of computer code (Focus today)
MATLAB TUTORIAL Dmitry Drutskoy Some material borrowed from the departmental MATLAB info session by Philippe Rigollet Kevin Wayne.
Dr. Jie Zou PHY Welcome to PHY 3320 Computational Methods in Physics and Engineering.
Approximation of u
What is MATLAB ? MATrix LABratory –Originally, it was a front-end to FORTRAN matrix routines developed in the U. of New Mexico and Stanford –Today.
Matlab tutorial course Lesson 2: Arrays and data types
Martin Ellison University of Warwick and CEPR Bank of England, December 2005 Introduction to MATLAB.
Timing Trials An investigation arising out of the Assignment CS32310 – Nov 2013 H Holstein 1.
Final Project CEE-101s-01/MATLAB
COMP 116: Introduction to Scientific Programming Lecture 6: Scripts and publishing, Creating matrices.
INTRODUCTION TO MATLAB LAB# 01
Numerical Computation Lecture 2: Introduction to Matlab Programming United International College.
Acute angle An angle with a measure less than 90 degrees.
Introduction to MATLAB Session 3 Simopekka Vänskä, THL Department of Mathematics and Statistics University of Helsinki 2011.
1 Lab 2 of COMP 319 Lab tutor : Shenghua ZHONG Lab 2: Sep. 28, 2011 Data and File in Matlab.
1 Week 2: Variables and Assignment Statements READING: 1.4 – 1.6 EECS Introduction to Computing for the Physical Sciences.
Recap Script M-file Editor/Debugger Window Cell Mode Chapter 3 “Built in MATLAB Function” Using Built-in Functions Using the HELP Feature Window HELP.
Computing Actual Lengths from a Scale Drawing. Scale Where have you seen this term used? Scale is the ratio of size between the actual object and a model.
Recap Sum and Product Functions Matrix Size Function Variance and Standard Deviation Random Numbers Complex Numbers.
Scientific Computing Introduction to Matlab Programming.
Introduction to MATLAB Session 1 Simopekka Vänskä, THL 2010.
Scientific Computing General Least Squares. Polynomial Least Squares Polynomial Least Squares: We assume that the class of functions is the class of all.
Introduction to MATLAB Session 5 Simopekka Vänskä, THL 2010.
ENG College of Engineering Engineering Education Innovation Center 1 Array Accessing and Strings in MATLAB Topics Covered: 1.Array addressing. 2.
CDA6530: Performance Models of Computers and Networks Chapter 8: Statistical Simulation --- Discrete-Time Simulation TexPoint fonts used in EMF. Read the.
Introduction to Matlab By E. Noura Semary. Contents MATLAB Environment  Command window, Workspace, Path window, Editor window,and Figure window) Basic.
Lec-10 Manipulations of Matlab Matrices. Built-in functions The chapter will be covered quickly There are quite a few built-in functions in MATLAB – If.
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
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 methods to solve diffusion equations A tutorial for biologists E. Grenier.
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.
1 Lecture 5 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
September 15, 2005 Lecture 5 - By Paul Lin 1 CPET 190 Lecture 5 Problem Solving with MATLAB
1 Lecture 3 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
Intro to Matlab Rogelio Long September 3, How to access MyDesktop Log in with your utep id and password.
Matlab Tutorial Iman Moazzen First Session – September 11, 2013.
Introduction to Matlab Engr. Mian Shahzad Iqbal LAB NO.2
State Space Models The state space model represents a physical system as n first order differential equations. This form is better suited for computer.
PATTERN RECOGNITION LAB 2 TA : Nouf Al-Harbi::
Introduction to programming in java Lecture 21 Arrays – Part 1.
COMPUTER GRAPHICS AND LINEAR ALGEBRA AN INTRODUCTION.
Matrix Mayhem: Outline
By Di Zhang TIES328:Matlab exercise 1 By Di Zhang
Linear Filters and Edges Chapters 7 and 8
Linear Filters and Edges Chapters 7 and 8
EE 4780 Matlab tutorial.
Seminar 1 for DCSP Using Matlab.
Matlab Workshop 9/22/2018.
StatLab Workshop: Intro to Matlab for Data Analysis and Statistical Modeling 11/29/2018.
TexPoint fonts used in EMF.
Department of Computer Science University of York
CS100A Lecture 21 Previous Lecture This Lecture
ME 123 Computer Applications I Lecture 5: Input and Output 3/17/03
Presentation transcript:

Problems and solutions Session 3

Introduction to MATLAB - Solutions 3 Problems 1. Write function Xn = mspolygon(X,x0,a) that scales the INPUT polygon by a (a>0) and moves its center to point x0, and draws both polygons in one image.  The polygon is given by matrix X whose columns are the nodes (corner points) of the polygon. The output Xn is the nodes of new polygon.  Define the centerpoint to be the average of the nodes.  Test your function with P of Exercise 1/Session 2.

Introduction to MATLAB - Solutions 3 Problems 2. Write a function Xt = roundt(X,t) that rounds real numbers to grid tZ = (…,-2t,-t,0,t,2t,…) and complex numbers to grid tC = tZ+itZ. The input X can be a matrix and t>0. Test your function (real case) with X = -5:.01:5 and t=sqrt(2)/2. Draw a picture. Test your function (complex case) with X = randn(1,5)+2*i*randn(1,5) and t=0.5. Draw a picture. Write both test cases in one m-file.

Introduction to MATLAB - Solutions 3 Problems 3. Continue the Triangle Exercise 7/Session 2. a) Write a function xn = Qpoints(n) where the input argument n is a vector n(j) = number of random points in [0,1]x[0,1] (e.g. n = 1000:1000:10000) and xn is a cell array with xn{j} = n(j) random points. b) Call Qpoints many times to find an approximative error when computing the area of T with different n’s. Represent the results graphically.

Introduction to MATLAB - Solutions 3 Some solutions 1. function Xn = mspolygon(X,x0,a); Xsc = a*X; Xn = [Xsc(1,:)+x0(1);Xsc(2,:)+x0(2)]; CALL Xn = mspolygon(P,[2;1],0.75); plot(P(1,:),P(2,:),’b’,Xn(1,:),Xn(2,:),’r’) 2. function Xt = roundt(X,t); Xt = t*round(X/t); CALL X = -5:.01:5; Xt = roundt(X,sqrt(2)/2); plot(X,Xt,’.’) Z = round(1,5)+2*i*round(1,5); Zt = roundt(Z,0.5); plot(Z(1,:),Z(2,:),’o’,Zt(1,:),Zt(2,:),’rx’)

Introduction to MATLAB - Solutions 3 Some solutions 3. function xn = Qpoints(n); nn=length(n); xn = cell(n,1); for j = 1:nn xn{j} = rand(2,n(nn)); end --- A routine to compute the area of T: --- function aT = areaT(xn) % area of T computed with xn (cell) nn = length(xn); aT = zeros(nn,1); for j = 1:nn x = xn{j}; aT(j) = sum(x(2,:)<(1-x(1,:)))/size(x,2); end Main m-file: % number of points –vector: n = [1, 10, 100,1000,10000,100000]; nn = length(n); % number of rounds: N = 1000; aTall = zeros(n,N); for k = 1:N % compute the areas N times xn = Qpoints(n); aTall(:,k) = areaT(xn); end deviations = std(aTall’) % histograms, nn even for k = 1:nn subplot(2,nn/2,k) hist(aTall(k,:)) end