Download presentation

Presentation is loading. Please wait.

Published byLyndsey Bash Modified about 1 year ago

1
March R. Smith - University of St Thomas - Minnesota Today’s Class Quiz RecapQuiz Recap Exam ReviewExam Review C MaterialC Material Matlab MaterialMatlab Material Why C? Why Matlab?Why C? Why Matlab?

2
March R. Smith - University of St Thomas - Minnesota Quiz Recap: Functions in C Functions have a HEADERFunctions have a HEADER –The header gives the type, the name, and the argument list –You need the header and the curly braces around the whole thing. Functions get inputs from ARGUMENTSFunctions get inputs from ARGUMENTS Functions send results through RESULTFunctions send results through RESULT –A ‘void’ function returns NO result Side Effects: ONLY if there’s I/O, or changes an ARGUMENTSide Effects: ONLY if there’s I/O, or changes an ARGUMENT

3
March R. Smith - University of St Thomas - Minnesota Final Exam – WHEN? Where? Here.Where? Here. When? …When? …

4
March R. Smith - University of St Thomas - Minnesota Final Exam – Section 2 (Morning) After Thursday, contact Oliver about examsAfter Thursday, contact Oliver about exams Section 2 (Morning) Exam:Section 2 (Morning) Exam: –Wednesday Dec 17 –8:00-10:00 AM

5
March R. Smith - University of St Thomas - Minnesota Final Exam – Section 3 (Afternoon) After Thursday, contact Oliver about examsAfter Thursday, contact Oliver about exams Section 3 (Afternoon) Exam:Section 3 (Afternoon) Exam: –Tuesday Dec 16 –1:30-3:30 PM

6
March R. Smith - University of St Thomas - Minnesota What is on the exam? Writing functions in CWriting functions in C Writing functions in MatlabWriting functions in Matlab Doing the same things in bothDoing the same things in both –I.e. 1 dimensional vectors and 1 dimensional arrays A loop and some IF statementsA loop and some IF statements –Solving problems with summations –Dealing with character codes and text Explaining why one might be better than the other for a particular problemExplaining why one might be better than the other for a particular problem

7
March R. Smith - University of St Thomas - Minnesota Looking at the Cheat Sheet Studying: you should know how to use EVERYTHING on the Cheat Sheet.Studying: you should know how to use EVERYTHING on the Cheat Sheet. C MatlabMatlab SummationsSummations Function FormatsFunction Formats Other SyntaxOther Syntax

8
March R. Smith - University of St Thomas - Minnesota Sum of integers 1 through N int sumi (int n) { int i;// index for the for loop int t;// total of the sum t = 0; for (i = 1; i <= n; i++) { t = t + i; } return t; }

9
March R. Smith - University of St Thomas - Minnesota Sum of a vector K with N elements int sumk (int k[], int n) { int i;// index for the for loop int t;// total of the sum t = 0; for (i = 0; i < n; i++) { t = t + k[i]; } return t; }

10
March R. Smith - University of St Thomas - Minnesota Exam Strategy If you don’t know what to doIf you don’t know what to do –Look at the Cheat Sheet –Find something about the problem Once you’ve answered a problemOnce you’ve answered a problem –Look up the specifics on the Cheat Sheet –Be sure you got the syntax correct –Be sure you used the right operators and functions Use “=“ for assignment. Use “==“ for ‘if’ and ‘while’Use “=“ for assignment. Use “==“ for ‘if’ and ‘while’

11
March R. Smith - University of St Thomas - Minnesota Matlab Functions Syntax:Syntax: function answer = name ( arguments ) % comment on how to use it statements ; File name.m must match function nameFile name.m must match function name List of zero or more arguments separated by commasList of zero or more arguments separated by commas Must set answer to legitimate valueMust set answer to legitimate value Executes statements till the end of the function fileExecutes statements till the end of the function file Exam will have ‘single result’ functions (like C)Exam will have ‘single result’ functions (like C)

12
March R. Smith - University of St Thomas - Minnesota Matlab IF/Else Typical Syntax:Typical Syntax: if ( expression1 ) statement1 ; elseif ( expression2 ) statement2 ; else statement3 ; end ALWAYS needs the end statement to mark the endALWAYS needs the end statement to mark the end No curly bracesNo curly braces

13
March R. Smith - University of St Thomas - Minnesota Matlab FOR Syntax:Syntax: for variable = vector statements ; end Goes through vector, element by elementGoes through vector, element by element –Assigns an element to variable –The vector can be a colon statement, like 1:length(x) Runs the statements until end, then repeatsRuns the statements until end, then repeats ALWAYS needs the end statement to mark the endALWAYS needs the end statement to mark the end No curly bracesNo curly braces

14
March R. Smith - University of St Thomas - Minnesota Matlab WHILE Syntax:Syntax: while expression statements ; end Tests expression for non-zero result, loops if soTests expression for non-zero result, loops if so Runs the statements until end, then repeatsRuns the statements until end, then repeats ALWAYS needs the end statement to mark the endALWAYS needs the end statement to mark the end No curly bracesNo curly braces

15
March R. Smith - University of St Thomas - Minnesota Why C? Why Matlab? The exam will ask you to explain why it’s better to use one or the other for various problemsThe exam will ask you to explain why it’s better to use one or the other for various problems

16
March R. Smith - University of St Thomas - Minnesota Choosing between C and Matlab Matlab is Better for…Matlab is Better for… Vector and matrix mathVector and matrix math –When sizes aren’t known ahead of time –When sizes might vary from one vector to another Graphing – it’s built inGraphing – it’s built in Processing standard file formats – built inProcessing standard file formats – built in –Images and spreadsheets C is Better for… Group programming –Established ways of sharing the work Tight quarters –When the computer is too small to run Matlab Little or no OS support –Computer doesn’t have graphics, not very interactive Access to I/O hardware –Easy to manipulate I/O control registers from C

17
March R. Smith - University of St Thomas - Minnesota Creative Commons License This work is licensed under the Creative Commons Attribution-Share Alike 3.0 United States License. To view a copy of this license, visit sa/3.0/us/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.

Similar presentations

© 2016 SlidePlayer.com Inc.

All rights reserved.

Ads by Google