Let’s stay fresh with C. What does this print? void mystery(int * x); main(){ int a = 5; mystery(&a); printf("%d\n",a); } void mystery(int * x){ int y;

Slides:



Advertisements
Similar presentations
2.3 Modeling Real World Data with Matrices
Advertisements

Lab # 03- SS Basic Graphic Commands. Lab Objectives: To understand M-files principle. To plot multiple plots on a single graph. To use different parameters.
Introduction to Graphing Using MATLAB. Line Graphs  Useful for graphing functions  Useful for displaying data trends over time  Useful for showing.
MATLAB’s extensive, device-independent plotting capabilities are one of its most powerful features. They make it very easy to plot any data at any time.
ספטמבר 04Copyright Meir Kalech1 C programming Language Chapter 3: Functions.
Computer Science 1620 Multi-Dimensional Arrays. we used arrays to store a set of data of the same type e.g. store the assignment grades for a particular.
1 Chapter 9 Arrays and Pointers. 2  One-dimensional arrays  The Relationship between Arrays and Pointers  Pointer Arithmetic and Element Size  Passing.
R-1 University of Washington Computer Programming I Lecture 17: Multidimensional Arrays © 2000 UW CSE.
1 CS 201 Array Debzani Deb. 2 Having trouble linking math.h? Link with the following option gcc –lm –o test test.o.
Chapter 7 Arrays C++ Programming, Namiq Sultan1 Namiq Sultan University of Duhok Department of Electrical and Computer Engineering Reference: Starting.
Lecture 9 Plotting in 2-D Plotting in 2-D, Plotting Multiple Curves, Plotting with Figures, Plot Settings, Scaling, Legends © 2007 Daniel Valentine. All.
Table of Contents Matrices - Multiplication Assume that matrix A is of order m  n and matrix B is of order p  q. To determine whether or not A can be.
Chapter 5 Review: Plotting Introduction to MATLAB 7 Engineering 161.
ENG College of Engineering Engineering Education Innovation Center 1 2D Plots 1 in MATLAB Topics Covered: 1.Plotting basic 2-D plots The plot()
Holt Algebra 2 4-1,4-2 Matrices and Data The table shows the top scores for girls in barrel racing at the 2004 National High School Rodeo finals. The data.
CMPS 1371 Introduction to Computing for Engineers PLOTTING.
„  1999 BG Mobasseri1 9/18/2015 June 2 GRAPHICS IN MATLAB- PART I BASIC PLOTTING.
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
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.
CSE 2341 Honors Professor Mark Fontenot Southern Methodist University Note Set 04.
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
Arrays- Part 2 Spring 2013Programming and Data Structure1.
Matlab Programming for Engineers Dr. Bashir NOURI Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
MATLAB for Engineers, by Holly Moore. ISBN © 2007 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is.
MAE 1202: AEROSPACE PRACTICUM An Introduction to MATLAB: Part 2 Mechanical and Aerospace Engineering Department Florida Institute of Technology Developed.
Multi-Dimensional Arrays Arrays that have more than one index: Example of differences between basic data types and arrays using integers: Basic integer:
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington 2D arrays COMP 102 # T1.
C++ Lecture 3 Monday, 14 July Arrays, Pointers, and Strings l Use of array in C++, multi- dimensional array, array argument passing l Pointers l.
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
A string is an array of characters Strings have many uses in MATLAB Display text output Specify formatting for plots Input arguments for some functions.
Structured Programming I – Relational & Logical Operators Objectives: By the end of this class you should be able to: Change graph interactively in EXCEL.
Recap Chapter 5 “Plotting” Two Dimensional Plots Simple x-y Plots Titles, Labels and Grids Multiple Plots.
EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,
Matrix Algebra Section 7.2. Review of order of matrices 2 rows, 3 columns Order is determined by: (# of rows) x (# of columns)
INTRODUCTION TO MATLAB DAVID COOPER SUMMER Course Layout SundayMondayTuesdayWednesdayThursdayFridaySaturday 67 Intro 89 Scripts 1011 Work
INTRODUCTION TO MATLAB Dr. Hugh Blanton ENTC 4347.
CCSA 221 Programming in C CHAPTER 7 WORKING WITH ARRAYS 1.
Pointers PART - 2. Pointers Pointers are variables that contain memory addresses as their values. A variable name directly references a value. A pointer.
ECE 103 Engineering Programming Chapter 23 Multi-Dimensional Arrays Herbert G. Mayer, PSU CS Status 6/24/2014 Initial content copied verbatim from ECE.
Arrays. Example Write a program to keep track of all students’ scores on quiz 1. Need a list of everyone’s score Declare 14 double variables? What about.
CS100A, Fall 1998, Lecture 191 CS100A, Fall 1998 Lecture 19, Thursday Nov 05 Matlab Concepts: Matlab arrays Matlab subscripting Matlab plotting.
CS100A, Fall 1998, Lecture 201 CS100A, Fall 1998 Lecture 20, Tuesday Nov 10 More Matlab Concepts: plotting (cont.) 2-D arrays Control structures: while,
Array Sort. Sort Pass 1 Sort Pass 2 Sort Pass 3.
Where do you sit?. What is a matrix? How do you classify matrices? How do you identify elements of a matrix?
How to use MATLAB (using M-files) Double click this icon To start Matlab 6.5.
Python Fundamentals: Complex Data Structures Eric Shook Department of Geography Kent State University.
1 Agenda Arrays: Definition Memory Examples Passing arrays to functions Multi dimensional arrays.
1 Two-Dimensional Arrays. 2 Terminology Two-dimensional arrays represent matrices A matrix contains a number of values of the same data type The values.
1 2-d Arrays. 2 Two Dimensional Arrays We have seen that an array variable can store a list of values Many applications require us to store a table of.
DYNAMIC MEMORY ALLOCATION. Disadvantages of ARRAYS MEMORY ALLOCATION OF ARRAY IS STATIC: Less resource utilization. For example: If the maximum elements.
Prof. N. P. Jadhav Presented by. Overview of MATLAB environment MATLAB is an interactive, matrix-based system for scientific and engineering numeric computation.
13.4 Product of Two Matrices
Computer Application in Engineering Design
Plotting Chapter 5.
Review of C… The basics of C scanf/printf if/elseif statements
Matrix Multiplication
Lecture 25: Exploring data
Numeric Arrays Numeric Arrays Chapter 4.
Arrays in C.
Matrices and Arrays.
MATLAB How to use (using M-files) Double click this icon
MATLAB How to use (using M-files) Double click this icon
MATLAB How to use (using M-files)
Warm-Up 3) 1) 4) Name the dimensions 2).
INTRODUCTION TO MATLAB
Plotting Signals in MATLAB
Functions continued.
Announcements P3 due today
Dimensions matching Rows times Columns
Presentation transcript:

Let’s stay fresh with C. What does this print? void mystery(int * x); main(){ int a = 5; mystery(&a); printf("%d\n",a); } void mystery(int * x){ int y; y = 2 * *x; *x = 3; } a) 5 b) 10 c) 6d) 3

What is the final value of a[4]? int i; float a[10]={1.0, 5.3, -2.1, 2.0}; for(i=1; i<10; i++){ a[i] = a[i-1]+a[i]; } a) 2 b) 6.2 c) undefinedd) 0.0

Which of the following is false about a function being passed an array? a) it knows the size of the array it was passed b) it is passed the address of the first element in the array c) it is able to modify the values stored in the array d) all of the above are true

Fill in the blank to print ? #define SIZE 10 void mystery(int a[], int num); main(){ int data[SIZE] = {1,2,3,4,5,6,7,8,9,10}; mystery(____________); } void mystery(int a[], int num){ int i; for(i=0; i<num; i++){ printf("%d ", a[i]); } printf("\n"); } a) data, 5 b) *data,5 c) data, SIZEd) data[SIZE]

Assume the variable x is stored at memory location 1000 and y is stored at memory location What are the values of x, y, and *y after executing the following block of C code? int x = 5; int *y; y = &x; x = 7; a) x = 7, y = 1004, *y = 7 b) x = 7, y = 1000, *y = 5 c) x = 7, y = 1000, *y = 7 d) x = 7, y = 5, *y = 5

What does this print out? #include int myFunction(int x[], int num); int main(void){ int result=0; int array[3] = {5, 2, -3}; result = myFunction(array,3); printf(“%d, %d\n”, array[1], array[2]); } int myFunction(int x[], int num){ x[1] = 4; x[2] = 7; return(x[1]+x[2]); } c) 4, 7 b) 5, 11 a) 5, 2 d) 2, 11

SWITCHING GEARS TO MATLAB…

Will this piece of code work? If not, why? >>A = [1 2 3; 3 5 6] >>B = [2 4 6; ] >>C = B*A This code will not work because ‘*’ is used for matrix multiplication and in matrix multiplication you need the same number of columns in B as rows in A.

Will this piece of code work? If not, why? >>A = [1 2 3; 3 5 6] >>B = [2 4 6; ] >>C = B.*A This code will work because ‘.*’ means multiply each element of B with the same element of A. In order to use ‘.*’, A and B need to be the same dimensions.

What does C store? >>A = [1 2 3; 3 5 6;1 2 1] >>B = [2 4 ; 6 1] >>C = B.*A(2:3,1:2) c) b) a) d)

What does B store? >>A = [1 2 3; 3 5 6;1 2 1] >>B = max(A) c)6 5 6 b)3 6 2 a) 6 d)3 5 6

What does C store? >>A = [1 2 3; 3 5 6;1 2 1] >>B = max(A) >>C=max(B) c)6 5 6 b)3 6 2 a) 6 d)3 5 6

What does B and C store? >>A = [1 2 3; 3 5 6;1 2 1] >>[B,C] = max(A) c)B = C = b)B = C = a)B= 6 C = 4 d)B = C = 2 2 2

What does D and E store? >>A = [1 2 3; 3 5 6;1 2 1] >>[B,C] = max(A) >>[D,E] = max(B) c)D = 6 E = 2 b)D = 6 E = 3 a)D= 6 E = 4 d)D = E = 3

TOPIC CHANGE: Exploring data

Define x and y and call the plot function

Engineers always add … Title title(‘y = cos(x)’) X axis label, complete with units xlabel(‘x-axis’) Y axis label, complete with units ylabel(‘y-axix’) Often it is useful to add a grid grid on Single quotes are used.

Creating multiple plots MATLAB overwrites the figure window every time you request a new plot To open a new figure window use the figure function – for example figure(2)

Create multiple lines on a single graph Each set of ordered pairs will produce a new line

If you want to create multiple plots, all with the same x value you can… Use alternating sets of ordered pairs plot(x,y1,x,y2,x,y3,x,y4) Or group the y values into a matrix z=[y1;y2;y3;y4] plot(x,z) x = 0:pi/100:2*pi; y1 = cos(x); y2 = cos(x)*2; y3 = cos(x)*4; y4 = cos(x)*6;

Line, Color and Mark Style You can change the appearance of your plots by selecting user defined line styles mark styles color Try using help plot for a list of available styles

Specify your choices in a string For example plot(x, y, ':ok') strings are identified with single quotes the : means use a dotted line the o means use a circle to mark each point the letter k indicates that the graph should be drawn in black  (b indicates blue)

Available choices Table 5. 2 Line, Mark and Color Options Line TypeIndicatorPoint TypeIndicatorColorIndicator solid-point.blueb dotted:circleogreeng dash-dot-.x-markxredr dashed--plus+cyanc star*magentam squaresyellowy diamonddblackk triangle downv triangle up^ triangle left< triangle right> pentagramp hexagramh

specify the drawing parameters for each line after the ordered pairs that define the line