L2: Functions, Conditionals, Problem-Solving, and Debugging

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/12

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

13 Terms

1
New cards
  1. state the problem clearly

  2. describe the input and output information

  3. work the problem (by hand or calculator) with a simple data set

  4. develop an algorithmic solution

    → use flow chart or pseudocode

  5. convert the solution to a computer program

  6. test the solution with a variety data sets

what are the six steps of problem solving

2
New cards
  1. something is known or given

  2. something is to be found, estimated or decided

  3. there is some condition to be satisfied or objective to achieve

how do we make sure we know we are solving the correct problem

3
New cards
  • 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

4
New cards

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

5
New cards

create adequate tests that consider edge cases

how do we debug a code

6
New cards
  • negative values

  • very large values

  • very small values

  • special values (e.g. 0,1 and -1)

  • identical inputs

what are examples of edge cases

7
New cards
  • 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

8
New cards

using the whos function

how can we see the type of variables we have in MATLAB

9
New cards
  • 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

10
New cards
  • == → 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

11
New cards
  • ~ → 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

12
New cards
  • 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

13
New cards

if <expression>

<statements>

elseif <expression>

<statements>

else

<statements>

end

how do conditional statements work