Lets Play with arrays Singh Tripty

Slides:



Advertisements
Similar presentations
Introduction to arrays
Advertisements

Matrix Multiplication To Multiply matrix A by matrix B: Multiply corresponding entries and then add the resulting products (1)(-1)+ (2)(3) Multiply each.
Arithmetic Operations on Matrices. 1. Definition of Matrix 2. Column, Row and Square Matrix 3. Addition and Subtraction of Matrices 4. Multiplying Row.
Section 10.3 – The Inverse of a Matrix No Calculator.
Chapter 7 Matrix Mathematics Matrix Operations Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
A.Abhari CPS1251 Multidimensional Arrays Multidimensional array is the array with two or more dimensions. For example: char box [3] [3] defines a two-dimensional.
13.1 Matrices and Their Sums
© Copyright 2013 by Pearson Education, Inc. All Rights Reserved. 1 Chapter 8 Multidimensional Arrays.
If A and B are both m × n matrices then the sum of A and B, denoted A + B, is a matrix obtained by adding corresponding elements of A and B. add these.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Class Opener:. Identifying Matrices Student Check:
Meeting 18 Matrix Operations. Matrix If A is an m x n matrix - that is, a matrix with m rows and n columns – then the scalar entry in the i th row and.
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. 1 Chapter 11 Lists for Multi-dimensional Data.
MULTI-DIMENSIONAL ARRAYS 1. Multi-dimensional Arrays The types of arrays discussed so far are all linear arrays. That is, they all dealt with a single.
If A and B are both m × n matrices then the sum of A and B, denoted A + B, is a matrix obtained by adding corresponding elements of A and B. add these.
2.1 Matrix Operations 2. Matrix Algebra. j -th column i -th row Diagonal entries Diagonal matrix : a square matrix whose nondiagonal entries are zero.
Chapter 5 Arrays F Introducing Arrays F Declaring Array Variables, Creating Arrays, and Initializing Arrays F Passing Arrays to Methods F Copying Arrays.
Arrays.
13.4 Product of Two Matrices
12-1 Organizing Data Using Matrices
Matrices Rules & Operations.
Linear Algebra review (optional)
Chapter 8 Multidimensional Arrays
Chapter 7 Matrix Mathematics
1.5 Matricies.
Chapter 7 Multidimensional Arrays
Chapter 8 Multidimensional Arrays
Dynamic Array Multidimensional Array Matric Operation with Array
Matrix Multiplication
MULTI-DIMENSIONAL ARRAY
Chapter 7: Array.
C Passing arrays to a Function
Chapter 8 Multidimensional Arrays
Arrays An Array is an ordered collection of variables
WarmUp 2-3 on your calculator or on paper..
Python I/O.
Substitution, Elimination, Graphing, Matrices
Chapter 8 Multidimensional Arrays
Chapter 7 Multidimensional Arrays
Chapter 5 Arrays Introducing Arrays
EKT150 : Computer Programming
25. Basic matrix operations
2. Matrix Algebra 2.1 Matrix Operations.
Multiplying Matrices.
Chapter 4 Systems of Linear Equations; Matrices
Chapter 8 Multidimensional Arrays
Chapter 8 Multidimensional Arrays
Section 2.4 Matrices.
Starting Out with Programming Logic & Design
Section 3.3 – The Inverse of a Matrix
Multidimensional Arrays
Chapter 8 Multidimensional Arrays
Multidimensional Arrays
What's wrong with Easter jokes? They crack you up
Multidimensional array
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
Chapter 8 Multidimensional Arrays
INC 161 , CPE 100 Computer Programming
Functions continued.
Chapter 7 Multidimensional Arrays
Multi-Dimensional Arrays
Linear Algebra review (optional)
Chapter 4 Systems of Linear Equations; Matrices
Chapter 7 Multidimensional Arrays
Chapter 8 Multidimensional Arrays
Arrays and Matrices Prof. Abdul Hameed.
Chapter 7 Multidimensional Arrays
Matrix Multiplication Sec. 4.2
Chapter 8 Multidimensional Arrays
Presentation transcript:

Lets Play with arrays Singh Tripty We will start with 1-D

Row X Column

To Calculate Average Using Arrays Program for while loop for loop and arrays To Calculate Average Using Arrays ARR[0] ARR[1] ARR[2] …… ARR[n]

Output Enter total number of elements(1 to 100): 8 Enter Number 1: 23.4 Enter Number 2: -34.5 Enter Number 3: 50 Enter Number 4: 33.5 Enter Number 5: 55.5 Enter Number 6: 43.7 Enter Number 7: 5.7 Enter Number 8: -66.5 This program takes n number of elements from user and stores it in array arr[]. To find the largest element, the first two elements of array are checked and largest of these two element is placed in arr[0]. Then, the first and third elements are checked and largest of these two element is placed in arr[0]. This process continues until and first and last elements are checked. Finally, the largest element of an array will be in arr[0] position. Check out these related examples:

How to pass arrays to a function in C Programming? Program to Calculate Standard Deviation To calculate the standard deviation, calculateSD() function is created. The array containing 10 elements is passed to the function and this function calculates the standard deviation and returns it to the main() function.

Now 2-D Matrix C Program to Add Two Matrix Using Multi-dimensional Arrays This program takes two matrices of order r*c and stores it in two-dimensional array. Then, the program adds these two matrices and displays it on the screen.

Program to Multiply Two Matrices To multiply two matrices, the number of columns of first matrix should be equal to the number of rows to second matrix. This program displays the error until the number of columns of first matrix is equal to the number of rows of second matrix.

Another example Problem Description This C Program finds the sum of the main & opposite diagonal elements of a MxN Matrix. The program accepts an MxN matrix. Then adds main diagonal of matrix as well as the opposite diagonal of the matrix. Problem Solution 1. Declare a matrix, taking order as input from users and define all its elements. 2. Declare two variable to store sum of each diagonal elements. 3. Run a for loop wherein the main diagonal element is given by index (i, i) where i is the iterator and opposite diagonal element is given by index(i, total_rows(m)-i-1). 4. The two variables are initialized to 0, which are summed up by diagonal elements. 5. Print the sum of diagonal elements.

Enter the order of the matix 2 2 Enter the co-efficients of the matrix Runtime Test Cases Enter the order of the matix 2 2 Enter the co-efficients of the matrix 40 30 38 90 The given matrix is 90 The sum of the main diagonal elements is = 130 The sum of the off diagonal elements is = 68

C Program to Multiply two Matrices by Passing Matrix to a Function To understand this example, you should have the knowledge of following C programming topics: C Programming Arrays C Programming Multidimensional Arrays How to pass arrays to a function in C Programming? This program asks the user to enter the size of the matrix (rows and column). Then, it asks the user to enter the elements of those matrices and finally adds and displays the result. To perform this task three functions are made: To takes matrix elements from user enterData() To multiply two matrix multiplyMatrices() To display the resultant matrix after multiplication display()

Finding transpose of a matrix The transpose of a matrix is a new matrix whose rows are the columns of the original. (This makes the columns of the new matrix the rows of the original). Here is a matrix and its transpose: The superscript "T" means "transpose