Test 2

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

1/116

flashcard set

Earn XP

Description and Tags

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

117 Terms

1
New cards

Truncation Errors

Refer to errors in a method, which occur because some series (finite or infinite) is truncated to a fewer number of terms.

Such errors are essentially algorithmic errors and we can predict the extent of the error that will occur in the method.

(e.g. π ≠ 3.14 ≠ 3.14159 but they are approximate)

2
New cards

Round-off errors

Round off error occurs because of the computing device's inability to deal with inexact numbers.

Such numbers need to be rounded off to some near approximation which is dependent on the space allotted by the device to represent the number

3
New cards

Absolute Error

= true value - approximation

Shortcoming: an error of a micrometer is much more significant if we are measuring the size of a cell in comparison to the length of your arm.

So how do we account for the size of the error with respect to the magnitude of the measurement?

4
New cards

Fractional Relative Error

= (Absolute error/true value)*100%

The relative error gives an indication of how good the approximation is relative to the true value

These will be needed when we talk about propagating errors (i.e. combining multiple values that each have an error associated with it)

5
New cards

Variance

a measure of how data points differ from the mean

<p>a measure of how data points differ from the mean</p>
6
New cards

Standard Deviation

a measure of variation of scores about the mean

the average distance to the mean, although that's not numerically accurate, it's conceptually helpful. All ways of saying the same thing: higher standard deviation indicates higher spread, less consistency, and less clustering

Square root of variance

std() provides the sample standard deviation

<p>a measure of variation of scores about the mean</p><p>the average distance to the mean, although that's not numerically accurate, it's conceptually helpful. All ways of saying the same thing: higher standard deviation indicates higher spread, less consistency, and less clustering</p><p>Square root of variance</p><p>std() provides the sample standard deviation</p>
7
New cards

Dot-operations

use the “.” for element-by-element level

So use .* or ./ or .^ instead of * or / or ^

8
New cards

Matrix multiplication vs array multiplication

Use “.” before operator for array calculations

<p>Use “.” before operator for array calculations</p>
9
New cards

Defining Matrices

Enclosed in square bracket [ ]

Commas separate columns

Semicolons indicate a new row

<p>Enclosed in square bracket [ ]</p><p>Commas separate columns</p><p>Semicolons indicate a new row</p>
10
New cards

Indexing arrays

Indexing can also be used to change values in a matrix or include additional values

11
New cards

Colon notation

Can be used to define evenly spaced vectors with a defined increment in the form:

first:increment:limit

12
New cards

linspace

Can be used to define evenly spaced vectors with a in the form

linspace(X1, X2, N)

generates N points between X1 and X2

13
New cards

Transpose

changes all of the rows of an array to columns and all of the columns to rows, B=A’

14
New cards

Concatenation

Creating a new matrix out of two previous matrices added as separate rows, C=[A; B]

<p><span>Creating a new matrix out of two previous matrices added as separate rows, C=[A; B]</span></p>
15
New cards

Plotting in 2D

  1. Create 2 vectors

  2. Use the plot(x,y,’format’) command

  3. Will create a plot of y vs x

  4. Format examples in pic

  5. To plot again of same plot use the hold on command

<ol><li><p>Create 2 vectors</p></li><li><p>Use the plot(x,y,’format’) command</p></li><li><p>Will create a plot of y vs x</p></li><li><p>Format examples in pic</p></li><li><p>To plot again of same plot use the hold on command</p></li></ol>
16
New cards

Subplots

Allows for putting multiple graphs in one figure

subplot(m,n,p) divides graphing window into a grid of m rows and n columns, where p identifies the part of the window where the plot will be drawn

<p>Allows for putting multiple graphs in one figure</p><p>subplot(m,n,p) divides graphing window into a grid of m rows and n columns, where p identifies the part of the window where the plot will be drawn</p>
17
New cards

Polar plots

To plot polar coordinates (angle vs radius) use polar(angle,radius)

<p>To plot polar coordinates (angle vs radius) use polar(angle,radius)</p>
18
New cards

Logarithmic plots

3 kinds:

  • semilogx

  • semilogy

  • loglog

Replace linear scales with logarithmic scales

<p>3 kinds:</p><ul><li><p>semilogx</p></li><li><p>semilogy</p></li><li><p>loglog</p></li></ul><p>Replace linear scales with logarithmic scales</p>
19
New cards

Linear regression

minimizes the squared distance between experimental data points and the modeled data points. This prevents positive and negative values from cancelling each other out

Use polyfit(x,y,polynomial degree) function with polyval() if necessary

<p>minimizes the squared distance between experimental data points and the modeled data points. This prevents positive and negative values from cancelling each other out</p><p>Use polyfit(x,y,polynomial degree) function with polyval() if necessary</p>
20
New cards

fplot

“smart” command for plotting functions

Automatically analyzes the function to be plotted and decides number of plotting points to show all the features of the function

fplot(function,[xmin xmax])

<p>“smart” command for plotting functions</p><p>Automatically analyzes the function to be plotted and decides number of plotting points to show all the features of the function</p><p>fplot(function,[xmin xmax])</p>
21
New cards

3D plots

plot3

graphs of 3 axes

<p>plot3</p><p>graphs of 3 axes</p>
22
New cards

Surface mesh plots

meshgrid()

mesh(,,)

Create a rectangular grid out of an array of x values and an array of y values

To fill in the faces of the surface in color use

meshgrid()

surf(,,)

<p>meshgrid()</p><p>mesh(,,)</p><p>Create a rectangular grid out of an array of x values and an array of y values</p><p>To fill in the faces of the surface in color use</p><p>meshgrid()</p><p>surf(,,)</p>
23
New cards

Contour Plots

a 3-D surface by plotting lines that connect points with common z-values along a slice

<p> a 3-D surface by plotting lines that connect points with common z-values along a slice</p>
24
New cards

Things plots need

  • a title

  • axis label with the name of quantity and units

  • same symbol of each data point in a given data set

  • grid

  • a legend

  • regularly spaced tick marks at convenient intervals along each axis.

25
New cards

Syntax Errors

Syntax errors are errors in a MATLAB statement itself, such as spelling or punctuation errors

<p>Syntax errors are errors in a MATLAB statement itself, such as spelling or punctuation errors</p>
26
New cards

Run time Errors

  • illegal operations

  • exceeds the dimensions of that matrix

27
New cards

Logical Errors

  • when the program runs without displaying an error, but produces an unexpected result

  • very difficult to find.

    • compare simple test cases with known correct results to find where errors occur

28
New cards

Less than

<

29
New cards

Greater than

>

30
New cards

Equal to

==

31
New cards

Less than or equal to

<=

32
New cards

Greater than or equal to

>=

33
New cards

Not equal to

~=

34
New cards

Logical Operator

Produces logical result (1 or 0), and &, not ~, or |

35
New cards

And (logical operator)

&

is true when all of its operands are true

36
New cards

Not (logical operator)

~

is true when its operand is false

37
New cards

Or (logical operator)

|

is true when one or more of its operands are true

38
New cards

Hierarchy of Operations

  1. Parentheses ()

  2. Exponentiation (.^)

  3. NOT operator (~)

  4. Multiplication (.*) and division (./)

  5. Addition (+) and subtraction (-)

  6. Less than (<), less than or equal to (<=), greater than (>), greater than or equal to (>=), equal to (==), and not equal to (~=)

  7. AND operator (&)

  8. OR operator (|)

39
New cards

VPA Arithmetic

MuPAD, vpa(), variable precision

in between for time and accuracy

Alternatives:

  • Rational MuPAD: more accurate, exact result, slowest

  • Numeric MATLAB: less accurate, faster, floating point

40
New cards

is Functions

ischar() input is character array

isfinite() input is finite

isinf() input isinfinite

isletter() input is alphabetic letter

isnumeric() input is numeric array

41
New cards

Pseudocode

Verbal description of your plan for writing a program

Written in English or as a combination of MATLAB code and English

<p>Verbal description of your plan for writing a program</p><p>Written in English or as a combination of MATLAB code and English</p>
42
New cards

Flowcharts

graphical approach to creating a coding plan

Epecially appropriate for planning large or complicated programming tasks

<p>graphical approach to creating a coding plan</p><p>Epecially appropriate for planning large or complicated programming tasks</p>
43
New cards

if statement

allows us to execute a series of statements if a condition is true and to skip those steps if the condition is false

can add else statements and if else

<p>allows us to execute a series of statements if a condition is true and to skip those steps if the condition is false</p><p>can add else statements and if else</p>
44
New cards

Nested if statements

If statements can be nested within each other

Allow you to choose 2 parameters of interest

45
New cards

for loop

repeat a block of commands for a specified matrix which is known before the loop is executed

indexed

<p>repeat a block of commands for a specified matrix which is known before the loop is executed</p><p>indexed</p>
46
New cards

one loop _ be written inside another loop

one loop CAN be written inside another loop

Called a nested loop

47
New cards

while loops

Loops are MATLAB constructs that allow a sequence of MATLAB statements to be executed more than once

loops repeat a block of commands as long as an expression is true (1)

The loop ends when the expression is false (0) and any code following the loop (after the end) is then executed

useful for repeating a procedure an unknown number of times as long as a certain statement is true

can be used to acquire data in experiments

useful when a procedure needs to be repeated until a specific criterion is met

<p>Loops are MATLAB constructs that allow a sequence of MATLAB statements to be executed more than once</p><p>loops repeat a block of commands as long as an expression is true (1)</p><p>The loop ends when the expression is false (0) and any code following the loop (after the end) is then executed</p><p></p><p>useful for repeating a procedure an unknown number of times as long as a certain statement is true</p><p><span>can be used to acquire data in experiments</span></p><p>useful when a procedure needs to be repeated until a specific criterion is met</p>
48
New cards

Components of a while loops

<p></p>
49
New cards

Built-in timer function

tic toc

tic starts the timer

time elapsed since the timer was started is given by the built-in function toc

50
New cards

Writing Functions

  • function [output1 output2] = function_name(input1, input2, input3)

    • output1 = equation using inputs

    • output2 = equation using inputs

  • end

51
New cards

Data import/Export

  • uiimport(name)

  • xlsread(‘filename.xls’) - in matlab folder, read excel

  • xlswrite(‘filenamr.xls’, M) - writes array M into excel

  • load <filename>

52
New cards

Exponential Growth

population & linear growth, compound interest

Increasing, asymptotic to the left

y=Ce^kt

53
New cards

Exponential Decay

radioactive decay, depreciation, fluorescent decay, learning, sales, stress

y=C(1-e^-kt)

y=Ce^-kt

54
New cards

Logarithmic Growth

population growth with limiting factors, acidity, sound, sigmodal curve

y=1/(1+be^-kt)

y=a+b*ln(t)

55
New cards

Converting a for loop into a while loop

One can change any program written with a for loop into a program written using a while loop instead

Change the index matrix of the for loop into an expression or set of variables that can be used in the while loop

for index → i=0

while i<length(index);

commands;

i=i+1; end

<p>One can change any program written with a for loop into a program written using a while loop instead</p><p>Change the index matrix of the for loop into an expression or set of variables that can be used in the while loop</p><p><span>for index → i=0 </span></p><p><span>while i&lt;length(index); </span></p><p><span>commands; </span></p><p><span>i=i+1; end</span></p>
56
New cards

Converting a while loop into a for loop

while expression →

for index=data;

if expression break;

end;

commands;

end

57
New cards

Text File Types

  1. Binary - fast, complicated, “native” format, .xls, .doc, .mat

  2. ASCII - matlab, text editor, simple, .txt, .dat, .cvs

58
New cards

break statement

can be used to terminate a loop prematurely

cause termination of the smallest enclosing loop

59
New cards

How to improve loop efficiency

pre-allocating space for a placeholder variable before entering the loop

60
New cards

Command to display text and matrix values

fprintf()

61
New cards

Different place holders for fprintf

Need in the format-string in order for variable to show up in your display on the command window

%d - integer notation

%f - fixed point notation (decimal)

%e - exponential notation

%g - whichever is shorter between %f or %e (insignificant zeros do not print)

%c - character information

%s - string of characters

62
New cards

normal distribution/gaussian

a probability distribution that is symmetric about the mean, showing that data near the mean are more frequent in occurrence than data far from the mean. In graphical form, it appears as a "bell curve"

63
New cards

trapz(y)

MATLAB function for trapezoidal area under the curve

64
New cards

Normal Probability Plot

x values vs. z values or normplot(x)

right skew - plot bends up and left

left skew - plot bends down and left

short tail - less variance than expected

long tail - more variance than expected

65
New cards

What is the area of a normal curve within 1 standard deviation (between μ+σ and μ-σ)

68%

<p>68%</p>
66
New cards

What is the area of a normal curve within 2 standard deviations (between μ+2σ and μ-2σ)

95%

<p>95%</p>
67
New cards

What is the area of a normal curve within 3 standard deviations (between μ+3σ and μ-3σ)

99.7%

<p>99.7%</p>
68
New cards

Code for a gaussian distribution

f(x) = gaussmf(x, [std mu])

std is the standard deviation

mu is the mean

x is the parameter under scrutiny

69
New cards

The standard normal distribution (z)

All normal distributions can be converted into the standard normal curve by subtracting the mean and dividing by the standard deviation

The probabilities given the z is in a table

<p>All normal distributions can be converted into the standard normal curve by subtracting the mean and dividing by the standard deviation</p><p>The probabilities given the z is in a table</p>
70
New cards

_ continuous random variables are normally distributed

NOT ALL continuous random variables are normally distributed

71
New cards

How to tell if your data is normally distributed

  1. Look at the histogram! Does it appear bell shaped?

  2. Compute descriptive summary measures—are mean, median, and mode similar?

  3. Do 2/3 of observations lay within 1 std dev of the mean? Do 95% of observations lay within 2 std dev of the mean?

  4. Look at a normal probability plot—is it approximately linear?

72
New cards

Every physical quantity has:

A value or size

Uncertainty (or Error)

Units

<p>A value or size</p><p>Uncertainty (or Error)</p><p>Units</p>
73
New cards

Error propagation equation to the first order if (∆x)/x is small:

knowt flashcard image
74
New cards

Equation for error propagation with addition and subtraction

knowt flashcard image
75
New cards

Equation for error propagation with multiplication and division

knowt flashcard image
76
New cards

Result Formats

numeric value +- error margin units

  • floating point - scientific notation

  • rational - exact result

  • numeric - normal, general result

77
New cards

Errors in computational models

Those due to uncertainty in the formulation of the mathematical models and deliberate simplifications of the models

Caused by rounding, data uncertainty, and truncation

78
New cards

Truncation Errors

Results from using an approximation in place of an exact mathematical procedure

The difference between analytical and numerical solutions

79
New cards

Reasons for Math Modeling

  1. Import meaning to data

  2. Help obtain data

  3. Help solve for specific conditions

80
New cards

Analytical Model

full mathematical solution

81
New cards

Numerical Model

Eulers, new value = old value + slope*step size, finite difference

82
New cards

Zero Order vs First Order vs Second Order

0: no change

1st: Linear change with change in x

2nd: Quadratic change with change in x

83
New cards

Any smooth function can be approximated as a

Polynomial

84
New cards

As the degree of the polynomial approximation _ the _ accurate the approximation

As the degree of the polynomial approximation INCREASES the MORE accurate the approximation

(adding more terms reduce truncation error)

85
New cards

Model Error

Incomplete mathematical models

e.g: E=mc²

86
New cards

Techniques to solve for roots

  1. Graphically - rough and inaccurate

  2. Trial and Error (using excel) - long winded

  3. Automated methods (require an initial guess)

    1. Bracketing Methods - Robust

      • 2 initial guesses that “bracket” the root

    2. Open methods - Faster

      • 1 guess or more but no need to bracket

87
New cards

2 types of solutions for root finding

  1. Implicit (cyclic)

  2. Explicit (one specific solution)

88
New cards

Bracketing techniques for root finding

  1. Incremental Search

    • Can work

    • Very inefficient

  2. Bisection Method

  3. False Position Method

89
New cards

Bracketing Bisection Full Process

  • Given upper and lower bounds (xl and xu)

  • [ determine xr, value halfway between xl and xu

  • Calculate f(xr)*f(xl) and f(xr)*f(xu), or only one if a root is guaranteed

  • A negative value determines the side the root is on. 

  • f(xr)*f(xl) = -#, root on the left; f(xr)*f(xu) = -#, root on the right

  • Left: xr becomes xu. Right: xr becomes xl ]

  • Repeat bracketed until required degree of precision is met

90
New cards

False Position Method

  • Linear interpolation, root finding

  • Joins F(xl) and F(xu), intersection of line with x-axis = root estimate

  • Slope = [ F(xu) - F(xl) ] / [ xu - xl ] =>  [ F(xr) - F(xl) ] / [ xr- xl ]  or xl -> xr

    • xu-xr = [ F(xu)*(xu-xl) ] / [ F(xu) - F(xl) ]

  • Issues: multiple roots, one fixed point, poor convergence for high curvature

  • faster than other bracketing methods, robust

<ul><li><p>Linear interpolation, root finding</p></li><li><p>Joins F(xl) and F(xu), intersection of line with x-axis = root estimate</p></li><li><p>Slope = [ F(xu) - F(xl) ] / [ xu - xl ] =&gt;&nbsp; [ F(xr) - F(xl) ] / [ xr- xl ]&nbsp; or xl -&gt; xr</p><ul><li><p>xu-xr = [ F(xu)*(xu-xl) ] / [ F(xu) - F(xl) ]</p></li></ul></li><li><p>Issues: multiple roots, one fixed point, poor convergence for high curvature</p></li><li><p>faster than other bracketing methods, robust</p></li></ul>
91
New cards

Steps of False Position Method

  1. Start with 2 values that bracket a singular root, L and U

  2. Calculate slope between the to points (draw line)

  3. Where the line crosses the x axis is the x value for R (slope line y=0)

  4. Find the correlating y value for the X_r on the function line

  5. Last step:

    • If Y_r = 0 done

    • If Y_r * Y_l = pos replace L with R and repeat

    • If Y_r*Y_l = neg replace U with R and repeat

<ol><li><p>Start with 2 values that bracket a singular root, L and U</p></li><li><p>Calculate slope between the to points (draw line)</p></li><li><p>Where the line crosses the x axis is the x value for R (slope line y=0)</p></li><li><p>Find the correlating y value for the X_r on the function line</p></li><li><p>Last step:</p><ul><li><p>If Y_r = 0 done</p></li><li><p>If Y_r * Y_l = pos replace L with R and repeat</p></li><li><p>If Y_r*Y_l = neg replace U with R and repeat</p></li></ul></li></ol>
92
New cards

Open Methods Overview

  • fast

  • divergence issues sometimes

  • when they do converge they do so more quickly

  • require 1 starting value

  • 3 possible results

    • Diverge

    • Converge Overdamped

    • Converge Underdamped

  • Types

    • Fixed point iteration

    • Newton Raphson

93
New cards

Overdamped (Convergence)

logarithmic like plot gradually approaching actual value

<p>logarithmic like plot gradually approaching actual value</p>
94
New cards

Underdamped (Convergence)

oscillate around actual value with slowly decreasing amplitude

<p>oscillate around actual value with slowly decreasing amplitude</p>
95
New cards

Diverging (Convergence)

points away from actual value and gets further away over time

<p><span>points away from actual value and gets further away over time</span></p>
96
New cards

Fixed Point Iteration

  • Root finding open method

  • Rearranges function f(x)=0 to x=g(x)

    • done with algebraic manipulation or log or simply adding x to both sides

  • We use this to create a formula that predicts a new value of x as a function of a previous value

    • x(i+1) = g(xi)

  • Relative error = Ea = | [ x(i+1) - xi ] / x(i+1) | * 100%

  • Plot the x vs. g(x). Point of intersection = root

  • Spiral convergence or divergence

  • x0 -> g(x0) -> x=g(0) at x1 -> x1 -> etc.

<ul><li><p>Root finding open method</p></li><li><p>Rearranges function f(x)=0 to x=g(x)</p><ul><li><p>done with algebraic manipulation or log or simply adding x to both sides</p></li></ul></li><li><p>We use this to create a formula that predicts a new value of x as a function of a previous value</p><ul><li><p>x(i+1) = g(xi) </p></li></ul></li><li><p>Relative error = Ea = | [ x(i+1) - xi ] / x(i+1) | * 100%</p></li><li><p>Plot the x vs. g(x). Point of intersection = root</p></li><li><p>Spiral convergence or divergence</p></li><li><p>x0 -&gt; g(x0) -&gt; x=g(0) at x1 -&gt; x1 -&gt; etc.</p></li></ul>
97
New cards

Fixed point Iteration Visualized

Plot the x vs. g(x). Point of intersection = root

<p>Plot the x vs. g(x). Point of intersection = root</p>
98
New cards

Newton Raphson

  • Most widely used root finding method

  • Initial guess xi, extend tangent from the point [xi, F(xi)]

  • Point where tangent line crosses x-axis becomes improved estimate

  • F’(xi) = F(xi) / [ xi - x(i+1) ]

  • Fastest convergence, very efficient

  • Bad for: multiple roots, high curvature, local minima, sigmodal curves

    • Can have divergence or jumping between roots

    • Local min / max send estimate to - or + infinity lkk

  • x(i+1) = xi - F(xi)/F’(xi)

  • Backwards/Secant: x(i+1) = xi - F(xi) * [ xj - x(j-1) ] / [ F(xj) - F(xj-1) ]

<ul><li><p>Most widely used&nbsp;root finding method</p></li><li><p>Initial guess xi, extend tangent from the point [xi, F(xi)]</p></li><li><p>Point where tangent line crosses x-axis becomes improved estimate</p></li><li><p>F’(xi) = F(xi) / [ xi - x(i+1) ]</p></li><li><p>Fastest convergence, very efficient</p></li><li><p>Bad for: multiple roots, high curvature, local minima, sigmodal curves</p><ul><li><p>Can have divergence or jumping between roots</p></li><li><p>Local min / max send estimate to - or + infinity&nbsp;lkk</p></li></ul></li><li><p>x(i+1) = xi - F(xi)/F’(xi)</p></li><li><p>Backwards/Secant: x(i+1) = xi - F(xi) * [ xj - x(j-1) ] / [ F(xj) - F(xj-1) ]</p></li></ul>
99
New cards

MATLAB Root Finding

  • fzero(function, guess) → fzero( @x x²-9, 4)

    • Combo of bisection, secant, and inverse quadratic interpolation

    • can have guess as an interval [0 4] for positive roots

  • Polynomial - r=roots(c)  being a row matrix of the coefficients of the equation

  • Opp: poly(r) = coefficients

100
New cards

Measuring Slope

  • Forward Difference 

    • Slope = [ F(i+1) - F(i) ] / [ x(i+1) - x(i) ]

  • Backwards Difference 

    • Slope = [ F(i) - F(i+1) ] / [ x(i) - x(i+1) ]

  • Centered Difference

    • Slope = [ F(i+1) - F(i-1) ] / [ x(i+1) - x(i-1) ]