1/17
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
state the problem clearly
describe the input and output information
work the problem (by hand or calculator) with a simple data set
develop an algorithmic solution
→ use flow chart or pseudocode
convert the solution to a computer program
test the solution with a variety data sets
what are the six steps of problem solving
something is known or given
something is to be found, estimated or decided
there is some condition to be satisfied or objective to achieve
how do we make sure we know we are solving the correct problem
syntax error → issues with syntax (i.e., the structure of our code)
semantic/logic errors → issues that may arise from misunderstanding the specific, or logical mistakes in our coding
these errors can occur at compile-time or run-time
what are the two categories of errors that we may encounter
read the error message
interpret the error message
find the line where the error is occuring
attempt to fix the error
rerun the program to see if we have solved the error
how do we debug syntax errors
misreading or misunderstanding the specification
using the incorrect variable or mistyping variable names
forgetting about operator precedence
mixing up the order of a function’s input or output arguments
hard-coding values
forgetting to remove or comment out old code
what are common causes of algorithmic errors
reread the specification
identify the correct output and some intermediate values
find where the values start diverging from what we expect
begin by sparsely looking through the program to find general vicinity of the error with one or more of the following:
print out some intermediate values using the disp function
remove the semi-colon ; operators that suppress output
add breakpoints and use the debugger
attempt to fix the error
rerun the program to see if we have resolved the error
how do we debug algorithmic errors
Read and interpret the error message.
Debug up to the line of the error with breakpoints.
Identify what values (in the Workspace) might cause the error.
Find where we calculated the incorrect values and place breakpoints at these lines.
Debug again while stepping through breakpoints to pinpoint the error-causing line.
Attempt to fix the error.
Rerun the program to see if we have resolved the error.
how do we debug run-time errors
when your code doesn’t throw an error but isn’t producing the output you’d expect
→ these can be found by testing your code after it is written
what is a silent bug
create adequate tests that consider edge cases
how do we debug a code
negative values
very large values
very small values
special values (e.g. 0,1 and -1)
identical inputs
what are examples of edge cases
allows you to set breakpoints in our code which will stop the execution of a script or function at that particular point of the program
this allows you to see the state of the script or function at that point i.e., what variables exist and what are the values stored in them
how do the built-in debugging tools in MATLAB work
using the whos function
how can we see the type of variables we have in MATLAB
MATLAB has a data type known as logical
only has two possible values: 1 or 0
we can cast a variable to a logical type by using the logical function
a zero value will become a logical 0
logical 1 represents a true state
logical 0 represents a false state
what is a logical data type
== → equal to
e.g. A == B
~= → not equal to
e.g. A ~= B
> → greater than
e.g. A > B
< → less than
e.g. A < B
>= → greater than or equal to
e.g. A >=B
<= → less than or equal to
e.g. A <= B
what relation operators are used to represent the outcomes of comparison
~ → Find logical NOT
e.g. ~A
& → Find logical AND
e.g. A & B
| → Find logical OR
e.g. A | B
how do logical operators work
logical AND with short-circuit operators → A && B && C && D && E
logical OR with short-circuit operators → A || B || C || D || E
what are examples of short circuit logical operators
1) Parentheses ()
2) Power ^
4) logical NOT ~
5) Multiplication → *, division → /
6) Addition → +, subtraction → -
8) Equal to → ==, Not equal to → ~=, Greater than → >, Less than → <, Greater than or equal to → >=, Less than or equal to → <=
9) Element-wise AND → &
10) Element-wise OR → |
11) Short-circuit AND → &&
12) Short-circuit OR → ||
what is the operator precedence of MATLAB operators
if <expression>
<statements>
elseif <expression>
<statements>
else
<statements>
end
how do conditional statements work