Download presentation
Presentation is loading. Please wait.
Published byDeirdre Cornelia Whitehead Modified over 9 years ago
1
Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O 6.Operators 7.Library Functions 1
2
Finally, the von Neumann Architecture… The Von Neumann computer architecture is mostly what we use today. The architecture separates a computer in 3 major parts: – The Central Processing Unit (CPU) – The computer memory – The Input/Output (I/O) devices CPU + memory Screen=output Speakers=output Mouse=input Keyboard=input ? 2
3
Categories of software Software contains the instructions the CPU uses to run programs. There are several categories, including: – Operating systems (OS) – manager of the computer system as a whole – Software applications – commercial programs that have been written to solve specific problems – Compilers / Interpreters - to ‘translate’ programs written by people into something understandable by the machine 3
4
Generations of Languages used to write software 1) Machine language – also called binary language. Sequence of 0’s and 1’s. 2) Assembly language – each line of code produces a single machine instruction (add, subtract…), see bottom of page 11. 3) High-level language – slightly closer to spoken languages. addb,c adda,b a= a + b + c; This line does the same as the two above. 4
5
MATLAB… Is an interpreted language – does not require compilation, but instead has an interpreter running behind the scenes – MATLAB executes one line at a time, (stops if one line crashes, or code ends) – Compiled languages read the entire code before executing line1! Has an interactive environment – – “In the MATLAB environment, you can develop and execute programs that contain MATLAB commands. You can execute a MATLAB command, observe the results, and then execute another MATLAB command that interacts with the information in memory, observe its results and so on.” 5
6
Problem Solving Process 6 1.Problem Statement a.Diagram b.Assumptions 2.Solution Steps (manual solution) a.Theory / limitations b.Itemize specific steps (in order) as you solve the problem c.Identify results & verify accuracy 3.Computerize the solution a.Express the algorithm as steps general to any instance of the problem b.Translate the algorithm to lines of code c.Test and verify results
7
7 Frame #1 “The Command Window” Frame #2 “Current Directory” Frame #3 “Workspace” Frame #4 “Command History” “Your Calculator Screen” You can do exactly as on your calculator: add, subtract, divide, multiple, use parentheses to override the order of operations… Later on, you will realize you can do a LOT more in this frame. This frame shows the files (excel, text, Matlab files) that can immediately be used. It will show the variables that have been created. It will show all the commands executed previously.
8
Basic Data Manipulation A variable is a name given for a memory location “Assigning a value to a variable” means to place a value in the memory location associated with the variable name MATLAB usually shows what the variables are - in the Command Window, but also in the Workspace. 8
9
The keyword ans 9
10
Inputs What data type is the user asked for? – num_apples = input('How many WHOLE apples? '); The user is asked to provide a number. – name = input('Enter your name: ', 's'); The user is asked to provide a sequence of characters – i.e. a string. These are the only forms of the input() function. 10
11
Form #1. input() In the first form, only 1 prompt is inside the parentheses: num_apples = input('How many WHOLE apples? '); There is only one argument to the function. Arguments are inputs to the function – information being sent into the function so it can do its job. The one argument is the prompt string: 'How many WHOLE apples:' 11
12
Form #2. input(…,‘s’) In the second form of the input() function, there are TWO arguments: the prompt string, and another string: ‘s’ name = input('Enter your name: ', 's'); If this argument is present, it must be the letter 's' and no other letter! 1 st argument 2nd argument 12
13
Display with a specific format There are multiple ways to display the value of a variable 1.Use the semicolon appropriately 2.use the disp() built-in function 3.use the fprintf() built-in function Each is used for specific reasons 1.Debugging – finding problems with the code 2.Simple programs, simple results (the programmer’s use) 3.Formatted (“pretty”) output 13
14
Using fprintf() 1.fprintf(...) % is the built-in function 2.fprintf('format String InSeRtEd hErE!') % The format string allows you to put words and specify a format (UPPER CASE vs. Lower case, and punctuation only) 3.fprintf('format string with placeholders', list of vars comma-separated, one for each placeholder) % Placeholders allow a specific format to be set (aligned right, and 2 decimal places for example) 14
15
Using fprintf() Example: fprintf('His name is %s, he makes %f dollars/year and his age is %d.\n', his_name, his_income, his_age); Provides: His name is Fred, he makes 1234.560000 dollars/year and his age is 45. >>> 15
16
Vocabulary fprintf('The value in result is %f meters.', result); “function call” ‘format string’ “placeholder” (part of format string) variable to be printed 16
17
Most common placeholders Each data-type has a placeholder – Integer %d – Floats %f – Strings %s – A single letter %c 17
18
%d does NOT mean decimals! Example: fprintf('His name is %s, he makes %d dollars/year and his age is %d.\n', his_name, his_income, his_age); Provides: His name is Fred, he makes 1.234560e+003 dollars/year and his age is 45. >> 18
19
Special Characters Escape sequences can also be used within the format string: \n - this will create a new line when printing the string \t - tab (tabs the text to the right) Special characters: '' - this will place one apostrophe in the final sentence Example of all three: >> fprintf('%s''s age:\t\t%d years old\n\n', name, age); Fred's age:47 years old >> 19
20
Format Modifiers Once the base placeholder is ready, modifiers further change how the values are displayed. Complete Format Modifier form: _ _ _ _ _ _ _ 7 6 5 4 3 2 1 %-7.2f Left-justify the value TOTAL width to occupy Nb. of decimal places 2 3. 5 5 _ _ 7 6 5 4 3 2 1 - 3 4. 3 0 _ 7 6 5 4 3 2 1 - 6 6 9 7. 4 4 7 6 5 4 3 2 1 20
21
Operators & Operands Operators work on operands. There are 2 types of operands: 1.Numerical 1, 3.5, -47 2.Logical true, false Arithmetic operators ( +, -, /, *, ^ ) and relational operators (, >=, ==, ~= ) require numerical operands Boolean operators ( &&, ||, ~ ) require logical operands 21
22
Boolean Operators These operators take logical values and perform some operation on them to yield a logical value Two Boolean operators allow to combine logical expressions – && Logical AND – || Logical OR One Boolean operator allows to negate the result – ~ Logical NOT – “Negate”: turns true values into false, and false values into true 22
23
Operators: unary vs. binary Operators can be unary – taking only one operand: y = -x; opposite = ~result; Or binary operators – taking two operands: z = x * y; z = x + y; z = x – y; %both unary and binary! z = x / y; z = x ^ y; x >= 7 (x y) 23
24
Operators: Output values TypeInput valuesOutput values Arithmetic: Numbers Numbers e.g. 5 * 315 Relational:NumbersLogical e.g. 5 < 3false Boolean:LogicalLogical e.g. ~truefalse 24
25
What is a function? A function is like a box with holes in it. 25 Input Output The _________ function Magic sinsqrtfloorrandbazingawhy
26
Exam 1: Review Questions 26
27
Review Questions Software & Hardware: Provide a simple definition for software. Is a DVD hardware or software? 27
28
Review Questions Language generations: Sort the following languages in order of generation, low to high: MATLAB Machine Assembly Why do we say that computers work in "binary"? 28
29
Problem Solving Process: When solving the following problem, what is the first step? Write a computer program that will compute the volume of any right regular prism with 10 sides or less. Review Questions 29
30
Review Questions Developing Solutions: 30
31
Review Questions MATLAB Defaults: What is ans ? What does clear do? What about clc ? How do you suppress default output? 31
32
Data types: Describe the following types of data: – Integers whole numbers – Floats numbers with fractional portion – Strings sequences of characters Review Questions 32
33
Review Questions MATLAB Layout: What is the command window useful for? a)Performing quick commands to see results b)Everyday calculator operations c)Getting the help file of a specific built-in function d)Writing full scripts (Select all that apply) 33
34
Review Questions Input and Output: What is the purpose of the first argument in a call to input() ? How many arguments are needed to collect a string from the user? 34
35
Review Questions Output functions: Given the following place holder: %14.7f How many decimal places will be displayed? What is the total width occupied on the screen as a result of this format specifier? Is the output left- or right-justified? 35
36
Review Questions Output functions: Given the following MATLAB statement: fprintf('%11s''s income:\t$%-7.2f/year\n', name, paycheck); 1. Identify the escape sequence(s) used. 36 3. If paycheck holds the value 123456.789, what will be printed for the second placeholder? 2. If name holds the value 'Fred Flintstone', what will be printed for the first placeholder?
37
Review Questions Operators: Given the following operators: &, &&, |, ||, +, -, *, /, ~, <, =, == Identify the Boolean operators. Identify the Relational operators What about the other ones? 37
38
Review Questions Operators: What is the result of a Boolean operator? – Numerical value – Logical value What is the numerical value stored in the workspace for the logical “false” –1–1 –0–0 – Logical expressions are not stored in the workspace 38
39
Review Questions Identify the parts – provide the name for the item or action: 39 the_result = some_function ( ); val1, str2, int3 Name a MATLAB built-in function which could be used to determine divisibility. While examining code from another engineer, you discover this line: fix_val = fix(z, 2); Did s/he use this command correctly? If so, what does it do? If not, what is wrong? Is there a built-in MATLAB function that will find the cube root of a number? Library Functions:
40
RUN home STUDY hard SLEEP well SHOW UP for the exam. Good Luck! How to prepare for Test 1 40
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.