Computer Simulation Lab

Slides:



Advertisements
Similar presentations
BRIAN D. HAHN AND DANIEL T. VALENTINE THIRD EDITION Essential MATLAB® for Engineers and Scientists.
Advertisements

Introduction to MATLAB
Hyperbolic Functions.
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.
Inverse Hyperbolic Functions. The Inverse Hyperbolic Sine, Inverse Hyperbolic Cosine & Inverse Hyperbolic Tangent.
Graphs of the Other Trigonometric Functions Section 4.6.
Introduction to Matlab. Entering Commands Constants and Functions >> pi ans = >> eps ans = e-016 >> sin(pi/2) ans = 1 >> log(1000) ans =
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
Builtin and user defined functions
SUNY-New Paltz Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz “Lecture 3”
Predefined MATLAB Functions ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 MATLAB Programming Chapter 2.
1 TAC2000/ Protocol Engineering and Application Research Laboratory (PEARL) MATH Functions in C Language.
Introduction to MATLAB Computational Probability and Statistics CIS 2033 Section 003 Djordje Gligorijevic, Temple University, Fall 2015.
Introduction to Engineering MATLAB – 1 Introduction to MATLAB Agenda Introduction Arithmetic Operations MATLAB Windows Command Window Defining Variables.
MATLAB An Introduction to MATLAB (Matrix Laboratory) 1.
Matlab for Engineers Built-in Matlab Functions Chapter 3.
1 MATLAB Basics. 2 MATLAB Documentation /help/techdoc/ Matrix Algebra.
1 Functions ผศ. ดร. อนันต์ ผลเพิ่ม Anan Phonphoem
STANDARD FUNCTIONS Computer Programming Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
1 Week 2: Variables and Assignment Statements READING: 1.4 – 1.6 EECS Introduction to Computing for the Physical Sciences.
Introduction to Matlab
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
Visual Basic I Programming
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.
C++ Programming Lecture 9 Functions – Part I By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz SUNY-New Paltz “Lecture 2”
Fundamentals of Programming 20-ENFD-112 Sections 001 to 007 Instructor: Prof. Dieter Schmidt Lecture: Monday, Wednesday 3:00-3:50 Web page
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.
Limits Involving Trigonometric Functions
Lecture 24: Rough and Ready Analysis. MATLAB uses function names consistent with most major programming languages For example sqrt sin cos log.
MATLAB Lecture 1 염익준. Introduction MATLAB (MATrix LABoratory) a special purpose computer program optimized to perform engineering and scientific calculations.
Prof. K. V. Mali, Sinhgad College of Engineering, Pune-41.
Graphing Trigonometric Functions Chapter 4. The sine and cosine curves Graph y = sinx.
Outline What is MATLAB MATLAB desktop Variables, Vectors and Matrices Matrix operations Array operations Built-in functions: Scalar, Vector, Matrix Data.
Some “What’s the output” questions to get the day started… >>A = [1 2 3; 3 5 6] This statement stores the matrix: 1. A= 2. A= 3. A= 4. A= Ask Garvin’s.
Simple C Programs.
Some Useful MATLAB Functions
Part(2) MATLAB.
Today Variable declaration Mathematical Operators Input and Output Lab
Introduction To MATLAB
Arithmetic Operations
Numeric, Cell and Structural Arrays One of the strenghts of MATLAB is the capabilty to handle collection of numbers called ARRAYS. MATLAB refers to scalars,
ECE 1304 Introduction to Electrical and Computer Engineering
Built-in MATLAB Functions Chapter 3
BIL 104E Introduction to Scientific and Engineering Computing
Trigonometric Graphs 6.2.
TMF1414 Introduction to Programming
Computer programming Dr. Ivan A. Hashim.
Computer Simulation Lab
FUNCTIONS EXAMPLES.
Fundamental of Java Programming Basics of Java Programming
Introduction to Programming
INTRODUCTION TO MATLAB AM2032 JAYANTA MUKHERJEE.
Trigonometric Graphs 1.6 Day 1.
Fourth Year – Software Engineering
Introduction to MATLAB
Introduction to Matlab
Graphing Other Trig. Functions
class 5 retrieving a previous statement in Thonny or IDLE // %
Announcements P3 due today
月夜憶舍弟 戍鼓斷人行,邊秋一雁聲。 露從今夜白,月是故鄉明。 有弟皆分散,無家問死生。 寄書長不達,況乃未休兵。 杜甫
月夜憶舍弟 戍鼓斷人行,邊秋一雁聲。 露從今夜白,月是故鄉明。 有弟皆分散,無家問死生。 寄書長不達,況乃未休兵。 杜甫
Electrical and Computer Engineering Department SUNY – New Paltz
Electrical and Computer Engineering Department SUNY – New Paltz
Electrical and Computer Engineering Department SUNY – New Paltz
CHAPTER 3 Built-in MATLAB Functions
Electrical and Computer Engineering Department SUNY – New Paltz
Presentation transcript:

Computer Simulation Lab “Lecture 5” Electrical and Computer Engineering Department SUNY – New Paltz SUNY-New Paltz

MATLAB functions Mathematical Function Trigonometric Functions V = sqrt( (u * cos(a))^2 + (u * sin(a) - g * t)^2 ); Trigonometric Functions SUNY-New Paltz

MATLAB functions Utility Functions d = clock(); disp(‘This year is: ‘, num2str(d(1)) Utility Functions SUNY-New Paltz

Hot to Plot a Function x=f(t) Step 1: determine the scope of t, i.e. the lower and upper limit Step 2: construct the horizontal axis as vector t: t = 0: .01 : 10 Step 3: determine vector x as a function of t: x = sqrt(t) Step 4: plot the graph as: plot(t,x) SUNY-New Paltz

Trigonometric Functions sin(x) sine of x cos(x) cosine of x. tan(x) tangent of x. cot(x) cotangent of x. asin(x) arc sine (inverse sine) of x between −π/2 and π/2. acos(x) arc cosine (inverse cosine) of x between 0 and π. atan(x) arc tangent of x between −π/2 and π/2. atan2(y, x) arc tangent of y/x between −π and π. sinh(x) hyperbolic sine of x cosh(x) hyperbolic cosine of x, tanh(x) hyperbolic tangent of x.. asinh(x) inverse hyperbolic sine of x, i.e. ln(x + √x2 + 1). acosh(x) inverse hyperbolic cosine of x, i.e. ln(x + √x2 − 1) atanh(x) inverse hyperbolic tangent of x, i.e.1/2 ln[(1 + x)/(1 − x)]. sec(x) secant of x. csc(x) cosecant of x. SUNY-New Paltz

Trigonometric Functions (Exercises) Use the command window to plot a sin(t) for t between -4*pi to + 4*pi. Write a program to prompt the user to enter A and B (between 0 and 1) and then the program plots y(t) = A*sin(t) + B*sin(2*t), where t is between -2*pi and +2*pi. SUNY-New Paltz

Trigonometric Functions (Exercises) Write a program to prompt the user to enter a number between 0 and 2. If 0, plot cos(t), else if 1, plot a sin(t), otherwise plot sin2(t). SUNY-New Paltz

Mathematical Functions abs(x) absolute value of x. log(x) natural logarithm of x. log10(x) base 10 logarithm of x. pow2(x) 2x exp(x) value of the exponential function ex rand pseudo-random number in the interval [0, 1). realmax largest positive floating point number on your computer. realmin smallest positive floating point number on your computer rem(x,y) remainder when x is divided by y, e.g. rem(19, 5) returns 4 (5 goes 3 times into 19, remainder 4). max(x) maximum element of vector x. mean(x) mean value of elements of vector x. min(x) minimum element of vector x. cumsum(x) cumulative sum of the elements of x, e.g. cumsum(1:4) returns [1 3 6 10] prod(x) product of the elements of x ones(m, n) generates an n by m matrix of 1’s zeros(m, n) generates an n by m matrix of 0’s SUNY-New Paltz

Mathematical Functions (Exercises) Using the function pow2(x), write a program to list the powers of 2 from 0 to 16: SUNY-New Paltz

Mathematical Functions (Exercises)   v SUNY-New Paltz

Mathematical Functions (Exercises) Generate 1000 random numbers using rand(1,1000). Plot them. Use the mean() function to prove that the average of random numbers generated by the rand() is .5. Hint: generate a very large vector made of randomly generated numbers. SUNY-New Paltz

Mathematical Functions (Exercises) Write a program to use a for loop to evaluate the average of 100, 1000, 10,000 and 100,00 randomly generated numbers. In each iteration, it should print: the average of xxx numbers is yyy. Hint: your index of the for loop should go through the vector [100, 1000, 10000, 10000]. SUNY-New Paltz

Mathematical Functions (Exercises) Use a single short statement and the prod(x) function to find the factorial of a number . e.g., 5! Then write a short program to prompt the user to enter a number. The program should print, for example: (5)! = 120 SUNY-New Paltz

Mathematical Functions (Exercises) Use the ones() and zeros() function to generate a row vector of size 100 that has values of 50-1’s and 50-0’s; i.e. [1 1 1 1 1 1 …0 0 0 0] Use the ones() and zeros() function to generate a row vector of size 90 that has values of 30-2’s, 30-1’s and 30-0’s; i.e. [2 2 2 2 2 2 …1 1 1 1 1 1 … 0 0 0 0 0 0] SUNY-New Paltz

Utility Functions clock time and date in a six-element vector, e.g. the statements Date date in a string in dd-mmm-yyyy format, e.g. 02-Feb-2001, which is thankfully Y2K compliant! floor(x) largest integer not exceeding x, i.e. rounds down to nearest integer, e.g. floor(-3.9) returns -4, floor(3.9) returns 3 ceil(x) smallest integer which exceeds x, i.e. rounds up to nearest integer, e.g. ceil(-3.9) returns -3, ceil(3.9) returns 4 fix(x) rounds to the nearest integer towards zero, e.g. fix(-3.9) returns - 3, fix(3.9) returns 3 round(x) rounds to the integer nearest to x, e.g. round(4.49) returns 4, round(4.5) returns 5 plot(x,y) plot y versus x length(x) number of elements of vector x size(a) number of rows and columns of matrix a. sort(x) sorts elements of vector x into ascending order (by columns if x is a matrix). sign(x) returns -1, 0 or 1 depending on whether x is negative, zero or positive. SUNY-New Paltz

Utility Functions (Exercises) Use the clock() function to print: 2/23/2017 @ 3:05:42 SUNY-New Paltz

Utility Functions (Exercises) Use the clock() function measure the execution time of pause(2). SUNY-New Paltz

Utility Functions (Exercises) Use the clock() function to measure the execution time (in microseconds) of each iteration of the following loop for i=1:1000000 j=i^5; end SUNY-New Paltz

Rand() Function 1- Use rand(1,N) to generate a row vector of N random numbers between 0 and 1. Generate 100 random numbers between -.5 and .5 Test your results by using min() and max() SUNY-New Paltz

Utility Functions (Exercises) Use the floor() and rand() functions to generate 100 integers between 0 and 9. Use max() and min() to test your results. Use the ceil() and rand() functions to generate 100 integers between 1 and 10. Use max() and min() to test your results. SUNY-New Paltz

Utility Functions (Exercises) Write a program to prompt the user to enter vector1 and vector2. If the vector have the same lengths, the print the sum and difference of them. Otherwise, print: The vectors must be of the same size. Hint: use length() function. SUNY-New Paltz

Utility Functions (Exercises) Write a program to prompt the user to enter a vector. Then print the maximum and minimum values of the vector without using a for loop.* * You are not allowed to use min() and max() functions. Any other function from the Utility Functions may be used. SUNY-New Paltz