Electrical and Computer Engineering Department SUNY – New Paltz

Slides:



Advertisements
Similar presentations
The Logic of Hypothesis Testing Population Hypothesis: A description of the probabilities of the values in the unobservable population. Simulated Repeated.
Advertisements

Random variables 1. Note  there is no chapter in the textbook that corresponds to this topic 2.
1. Frequency Distribution & Relative Frequency Distribution 2. Histogram of Probability Distribution 3. Probability of an Event in Histogram 4. Random.
A.P. STATISTICS LESSON 7 – 1 ( DAY 1 ) DISCRETE AND CONTINUOUS RANDOM VARIABLES.
B a c kn e x t h o m e Frequency Distributions frequency distribution A frequency distribution is a table used to organize data. The left column (called.
Chapter 7. Even in quantitative sciences, we often encounter letters and/or words that must be processed by code You may want to write code that: Reads.
Biostatistics Unit 4 Probability.
Biostatistics Unit 4 - Probability.
Additional Data Types: Strings Selim Aksoy Bilkent University Department of Computer Engineering
MATLAB Strings Selim Aksoy Bilkent University Department of Computer Engineering
SUNY-New Paltz Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz “Lecture 3”
STATISTICAL GRAPHS.
Thinking Mathematically
SUNY-New Paltz Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz “Lecture 4”
Section 7.1 The STANDARD NORMAL CURVE
CSE123 Lecture 6 String Arrays. Character Strings In Matlab, text is referred to as character strings. String Construction Character strings in Matlab.
Mastering Char to ASCII AND DOING MORE RELATED STRING MANIPULATION Why VB.Net ?  The Language resembles Pseudocode - good for teaching and learning fundamentals.
Probability Distributions. Essential Question: What is a probability distribution and how is it displayed?
4.1 Probability Distributions. Do you remember? Relative Frequency Histogram.
Matlab Programming for Engineers Dr. Bashir NOURI Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
Chapter 10: Introducing Probability STAT Connecting Chapter 10 to our Current Knowledge of Statistics Probability theory leads us from data collection.
Histograms. Grouped frequency distribution Shows how many values of each variable lie in a class. Some information is lost. When presenting this information.
CPS120: Introduction to Computer Science Lecture 15 Arrays.
Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz SUNY-New Paltz “Lecture 2”
1. Comparing Strings 2. Converting strings/numbers 3. Additional String Functions Strings Built-In Functions 1.
Strings Characters and Sentences 1.Overview 2.Creating Strings 3.Slicing Strings 4.Searching for substrings 1.
PATTERN RECOGNITION LAB 2 TA : Nouf Al-Harbi::
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 this week – last section on Friday. Assignment 4 is posted. Data mining: –Designing functions.
Copyright © Cengage Learning. All rights reserved. 8 PROBABILITY DISTRIBUTIONS AND STATISTICS.
Draw, analyze, and use bar graphs and histograms. Organize data into a frequency distribution table The Frequency Distribution.
Graphing options for Quantitative Data
Chapter 2 Descriptive Statistics.
Computer Application in Engineering Design
Continuous Random Variables
© 2016 Pearson Education, Ltd. All rights reserved.
Control Statements in Matlab
EGR 115 Introduction to Computing for Engineers
Computer Simulation Lab
Outline Matlab tutorial How to start and exit Matlab Matlab basics.
The relational operators
Lecture 3 part-2: Organization and Summarization of Data
© Akhilesh Bajaj, All rights reserved.
Hello worLd, variables, arrays, plots, for loops, Simulation
MatLab – 2D Plots 2 MATLAB has many built-in functions and commands to create various types of plots. Instructor notes: We start with an example of some.
String Manipulation Chapter 7 Attaway MATLAB 4E.
Communication and Coding Theory Lab(CS491)
Chapter 2: Statistics and Graphs (pg. 81)
Islamic University of Gaza
Continuous Random Variables
‘If’ statements, relational operators, and logical operators
Using Script Files and Managing Data
The Normal Curve Section 7.1 & 7.2.
EECE.2160 ECE Application Programming
Constructing and Interpreting Visual Displays of Data
Matlab Basics.
Text Manipulation Chapter 7 Attaway MATLAB 5E.
Descriptive Statistics
Displaying data in Stem-and-Leaf Plots and Histograms
Discrete Random Variables: Joint PMFs, Conditioning and Independence
EECE.2160 ECE Application Programming
Trials & laws & Large Numbers (Large Number Theory)
Electrical and Computer Engineering Department SUNY – New Paltz
The Normal Distribution
Simulate Multiple Dice
Computer Simulation Lab
Computer Simulation Lab
Electrical and Computer Engineering Department SUNY – New Paltz
Electrical and Computer Engineering Department SUNY – New Paltz
Electrical and Computer Engineering Department SUNY – New Paltz
Presentation transcript:

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

Plots a bar-graph of a vector bar(v) Plots a bar-graph of a vector SUNY-New Paltz

Exercise Use bar() function to display a vector of prime numbers (1 thru 43). Hint: use primes() function. SUNY-New Paltz

Exercise In the previous exercise, use a for loop that will print the value of each bar on the top it. SUNY-New Paltz

Exercise Toss a coin N times (user selectable). Store the number of tails in x(1) and the number of heads in x(2). Then use bar(x) to compare them together. SUNY-New Paltz

Exercise Roll a die N times (user selectable). Store the number of ones in x(1) and the number of two’s in x(2) and so on. Then use bar(x) to compare them together. SUNY-New Paltz

Frequencies, bar charts and histograms A random walk Imagine an ant walking along a straight line, e.g. the x-axis. She starts at x = 40. She moves in Steps of one unit along the line. Each step is to the left or the right with equal probability. We would like a visual representation of how much time she spends at each position. SUNY-New Paltz

MATLAB Code bar(f) f = zeros(1,100); x = 40; for i = 1:1000 r = rand; if r >= 0.5 x = x + 1; else x = x - 1; end f(x) = f(x) + 1; End bar(f) SUNY-New Paltz

hist() What is a histogram? his·to·gram, ˈhistəˌɡram/ Noun, STATISTICS a diagram consisting of rectangles whose area is proportional to the frequency of a variable and whose width is equal to the class interval. SUNY-New Paltz

Exercise Use vectorization and hist() function to repeat the exercises on flipping a coin and rolling a die. Increase the number of trials to 1000, 10,000 and 1,000,000. SUNY-New Paltz

Exercise Generate row vector (128 elements) of random numbers between 0 and 1 and use imshow() to visualize it. Then use hist() function to see the distribution. Repeat the above for vector sizes 256, 512 and 1024 and draw a conclusion regarding the size of the vector. SUNY-New Paltz

Arrays of characters: strings Assignment: s = ’Hi there’; s = ’o’’clock’; Input: name = input(‘Enter Your Name:’) Enter Your Name: ’myname’ name = input(‘Enter Your Name:’,’s’) Enter Your Name: myname SUNY-New Paltz

Strings are arrays s = ’Napoleon’ s(8:-1:1) Concatenation of strings king = ’Henry’; king = [king, ’ VIII’] SUNY-New Paltz

ASCII Table SUNY-New Paltz

ASCII code Exercise Decode from ASCII to string: 69 71 69 45 51 51 49 What are the ASCII codes for: Carriage Return Linefeed SUNY-New Paltz

ASCII codes,double and char double(’Napoleon’) 78 97 112 111 108 101 111 110 char(65:70) ABCDEF x = char(ones(4,20)*double(’#’)) #################### SUNY-New Paltz

Exercise Write a program that prints all ASCII codes along with their corresponding characters in a single column. Show the above table in a multi-column form. SUNY-New Paltz

ASCII codes,double and char s = ’a’ s+1 char(s+1) alpha = double(’a’):double(’z’) SUNY-New Paltz

Comparing strings s1 = ’ann’; s2 = ’ban’; s1 < s2 1 0 0 1 0 0 SUNY-New Paltz

Other string functions blanks generates a string of blanks. deblank removes trailing blanks from a string. int2str, num2str convert their numeric arguments to strings. ischar returns 1 if its argument is a string, and 0 otherwise. lower, upper convert strings to lower- and uppercase respectively SUNY-New Paltz

Exercise Prompt the user to enter his/her name: First name separated from the last name by a blank. Print out the a string starting with the last name separated from the first name by a coma. Capitalize the first characters of the first and last names. SUNY-New Paltz

Matlab Code s = input('Enter Your Name(John Doe):','s') for i=1:length(s) if s(i) == ' ' s(1) = upper(s(1)); s(i+1)=upper(s(i+1)); s1=[s(i+1:length(s)),', ',s(1:i-1)] break; end SUNY-New Paltz

fprintf, fprintf( ’% 8sVIII\n’, ’Henry’ ) ؙؙؙHenryVIII Henry ؙؙؙ VIII HenVIII SUNY-New Paltz

sprintf Value of K: .015 K=.015 s = sprintf( ’Value of K: %g’, K ) SUNY-New Paltz

Two-dimensional strings nameAndAddress = [’Adam B Carr ’; ’21 Barkly Ave’; ’Discovery ’] nameAndAddress = Adam B Carr 21 Barkly Ave Discovery nameAndAddress = char(’Adam B Carr’, ’21 Barkly Ave’, ’Discovery’) double(nameAndAddress(1,12)) SUNY-New Paltz

Eval and text macros s = ’x = -b/(2*a);’ eval(s) x = -b/(2*a); Have the user enter a matlab function, such as sin(x), cos(x), etc. Your program should plot that function. SUNY-New Paltz

Code f = input( ’Enter function (of x) to be plotted: ’, ’s’ ); plot(x, eval(f)),grid Enter function (of x) to be plotted: exp(-0.5*x) .* sin(x) SUNY-New Paltz