Brush up on essential programming concepts including for loops, if statements, functions, and Excel formulas. Learn key differences, sorting techniques, and numerical methods. Practice creating formulas and performing calculations in Excel.
01 / 95Comprehensive Programming Review: For Loops, If Statements, Functions, and Excel Formulas
1 / 17
Télécharger la présentation
Comprehensive Programming Review: For Loops, If Statements, Functions, and Excel Formulas
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation
Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement.Téléchargez la présentation en cliquant sur ce lien.Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.
From the first half of the class • for loops, if, while, cout • the diff between if and else if • the diff between variables and functions • int presentValue; • int presentValue( ); • the diff between defining functions (outside of main) and calling functions (from main). int presentMenu(); choice = presentMenu(); int presentMenu( ) { main
if (a == b) { // do this } else if (c == d) // depends on a and b or if (c == d) // a and b are NOT critical { // do that }
this is cell C3 Row H6:K6 Column E7:E16 Rectangle J14:L18 know what a colon means
What is a formula? • A calculation using numeric data and cell values • Data may be numbers OR references to other cells • Excel performs calculation and displays the result, updating in real time • Excel updates cell formula if the cell containing it is moved
Entering a Formula • Always begins with the equals sign (=) • Use numbers and/or cell references • Use arithmetic operators + addition - subtraction / division * multiplication ( ) parentheses know what an equal sign means in Excel vs. C++
the best part Copy and paste are RELATIVE…Select cell, then: • Copy/Paste • CTRL + C copy • CTRL + V paste • Fill Handle • Move mouse over bottom right-hand corner of cell • It becomes a cross-hair (not an arrow) • Right-click and Drag to copy and paste formulas
Absolute References • Allows cell reference to remain same as its copy/pasted • Absolute: $A$1 • Mixed: A$1 or $A1 • Relative : A1 know what $ means
Common Functions • = SUM( range) • = AVERAGE( range ) • = MAX( range ) • = MIN( range ) • = STDEVP( range )
In flight, thethrustproduced by an aircraft’s engine is used to overcome the drag of flying through thick air. • Thrust and Drag are FORCES, measured in Newtons • Since the plane is flying through "liquid" air, • Power = VELOCITY x Force • is relevant to keeping the plane aloft.
Plot the Power Required and Power Available versus Flight Speed - use SCATTER rather than LINE plot (will pick leftmost column as the independent variable) know the difference between line and scatter (line uses cell row number as x axis and plots every column; scatter uses left column as x axis, and plots the right column(s)
variables type here files and folders know Command Window vs script (m) file. command history
some useful commands • variable (scalar) definition: x = 10 • a scalar is a single-valued variable, but MATLAB regards it as a 1x1 matrix • no semicolons needed, although a semicolon will stop echo • comments start with %, used mostly in scripts know what the semi-colon does in MATLAB vs. C++
m files • type commands into MATLABs "notepad" • load/save as usual • two ways to run: • hit the PLAY button • Type the filename at the command prompt know the difference between m and mat files.... mat files are the result of the s"save" command, and merely save your variables, not your commands
Matrix definition • a = [ 1 47 65 89 22] • b = [25 55 22 43 72] • c = a * b % dimensions? • d = b * a % dimensions?
You can try to define some special matrices E = ones(2,3) % ones(m,n) gives an m*n matrix of 1's F = eye(3) % The identity matrix eye(n) is a matrix of zeros except for having ones along its leading diagonal G = [-3 4 2], H = diag(G) % define a vector and give a diagonal matrix I = rand(1,3) % rand(m,n) gives m*n matrix of uniformly distributed random numbers on (0,1)
Individual Array elements • Let's start with the simple case of a vector and a single subscript. The vector is v = [16 5 9 4 2 11 7 14] • The subscript can be a single value. v(3) % Extract the third element ans = 9 • Colons work: v(1:4) ans = 16 5 9 4
Indexing Matrices with Two Subscripts • Now consider indexing into a matrix. A = 16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1 • indexing in matrices is done using two subscripts - one for the rows and one for the columns. A(2,4) % Extract the element in row 2, column 4 ans = 8
surface plot • x=[1:10] • y=transpose(x) • z= y * x • figure(1) • surf(x,y,z) • figure(2) • z = rand(10) • surf(x,y,z)
matrices • usually represent a table, or a data relationship • or - referring to C++ - correlated arrays 3 x + 4y + 16z = 12 3 4 16 12 6x - 17y - 23z = -168 6 -17 -23 = -168 x + 42y + 101 z = 140 1 42 101 140 3 equations in 3 unknowns, represented by matrices
matrix multiplication simple A * B = C each Row in A x each Col in B = (Row,Col) item in C a11b12 + a12b22 = c12
1 2 3 * 1 2 = 22 28 4 5 6 3 4 49 64 5 6 2 X 3 * 3 X 2 results in a 2 x 2 inner dimensions must be the same out dimensions reveal size
represent N equations in N unknowns 1) x + y − z = 4 2) x − 2y + 3z = −6 3) 2x + 3y + z = 7 1 1 -1 x 4 1 -2 3 * y = -6 2 3 1 z 7 know: coefficient matrix vs. variables matrix vs. constants matrix
the Identity Matrix (1s in the diagonal) Any matrix times an appropriately sized identity matrix yields itself 3x2 2x2 3x2 23 45 1 0 23 45 17 22 * 0 1 = 17 22 1 32 1 32 Size of ID matrix: SQUARE, dictated by COLUMNS of the multiplying matrix
what is a matrix inverse? • A matrix multiplied by it's Inverse yields the identity matrix • A * AI = Identity • "Singular" matrices have no Inverse
Why? A 1) x + y − z = 4 2) x − 2y + 3z = −6 3) 2x + 3y + z = 7 multiply both sides by AT: 1 1 -1 x 4 1 -2 3 * y = -6 2 3 1 z 7 x 4 AI * A * y = AI * -6 z 7 find AI, and you can solve for x, y, z
mat files Saving data: http://www.mathworks.com/help/techdoc/ref/save.html Setting output format: http://www.mathworks.com/help/techdoc/ref/format.html
Connexion au compte
Connectez-vous pour publier votre contenu sur SlideServe.