ENGR 1330 Exam 2

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

1/52

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.

53 Terms

1
New cards

File System

Controls how data is stored and retrieved.

2
New cards

Path

the general form of the name of a file or directory, specifies a unique location in a file system.

3
New cards

How do you get your current working directory?

os.getcwd( ) or %pwd

4
New cards

How do you change your current working directory

os.chdir( )

5
New cards

"r"

Read - Default value. Opens a file for reading, error if the file does not exist.

6
New cards

"a"

Append - opens a file for appending, creates the file if it does not exist.

7
New cards

"w"

Write - opens a file for writing, creates the file if it does not exist.

8
New cards

"x"

Create - Creates the specified file, returns an error if the file exists.

9
New cards

How do you delete a file?

os.remove( )

10
New cards

NumPy

The core library for scientific computing in Python. It provides a high-performance multidimensional array object, and tools for working with these arrays.

11
New cards

Arrays

a grid of values, all of the same type, and is indexed by a tuple of non-negative integers. The number of dimensions is the rank of the array; the shape of an array is a tuple of integers giving the size of an array along each dimension.

12
New cards

What are two ways to perform a matrix multiplication in two arrays?

Array1@Array2 or Array1.dot(Array2)

13
New cards

What does the axis define in an array?

axis = 0: columns , axis = 1: rows

14
New cards

What NumPy function converts degrees to radians?

np.deg2rad(degrees)

15
New cards

What would this code return in an array: (array[1:3, 1:4])

This will take the index of numbers from 1 to 4 from rows 1 and 2

16
New cards

What does the shape of an array mean and how do we check the shape of an array?

The shape of an array describes how many rows and columns in an array (rows, columns) and you can check the shape of an array with the function "array.shape"

17
New cards

How can you generate random numbers using the NumPy module?

np.random.randint

18
New cards

how can you transpose from rows to columns and vice versa?

vector_row.T (uppercase)

19
New cards

How can you get the cross product of two vectors?

(np.cross(v1, v2)

20
New cards

How can you find the determinant of an array?

det(x)

21
New cards

How can you find the identity matrix of an array?

np.identity(x.shape[0])

22
New cards

What is matplotlib.pyplot

a collection of functions allowing the creation of different graphs. Various states are preserved across function calls so that it keeps track of things like the current figure and plotting area.

23
New cards

Data models in matplotlib.pyplot

Has to be kept in sets which use curly brackets {'chocolate': 16, 'vanilla':13, 'strawberry':10}

24
New cards

What function creates a bar graph?

matplotlib.pyplot.bar

25
New cards

How can you modify the x-axis in a graph?

plt.xlabel(' ')

26
New cards

How can you make a scatter plot in matplotlib?

plt.scatter(' ')

27
New cards

How can you change the figure size in a graph?

plt.figure(figsize = (10,5))

28
New cards

How can you create two plots in one dataset?

plt.subplots( ) or (ax1,ax2) = plt.subplots(1,2)

29
New cards

Lambda function

a small, anonymous function defined using the lambda keyword. It can take any number of arguments but can only have one expression.

30
New cards

Bisection method

a method to find roots of a function f(x) within a given interval [a,b]. It works under the assumption that the function changes over the interval, meaning f(a) and f(b), the two initial guesses, must have opposite signs.

31
New cards

Requirements of the bisection method

- the function f(x) must be continuous within the given interval [a, b]

32
New cards

The function at the endpoints f(a) and f(b) must have _____ signs in the bisection method

opposite

33
New cards

Bisection method stopping criteria

The method stops when:

- the interval [a, b] becomes sufficiently small.

- the function value at the midpoint is close to zero.

- a maximum number of iterations in reached.

34
New cards

midpoint calculation

at each step, the midpoint c is calculated as c = a + b / 2

35
New cards

if f(a) * f(b) < 0

the root lies between a and c

36
New cards

if f(b) * f(c) < 0

the root lies between c and b

37
New cards

Bisection method (Convergence)

the method converges slowly but guarantees a root.

38
New cards

Secant method

a numerical method used for finding roots of a function. It approximates the derivative using values of the function at two points.

39
New cards

Secant method initial guesses

the secant method requires two initial guesses. However, unlike the bisection method, these guesses do not need to have opposite signs for their function values.

40
New cards

Secant formula

y = (f(b) - f(a)) / (b-a) * (x - a) + f(a)

41
New cards

Secant method stopping criteria

The method stops when:

- the difference between successive approximations is smaller than a tolerance value.

42
New cards

Secant method (convergence)

The method can converge faster than the bisection method, but it does not always guarantee convergence unless the initial guesses are close to the actual root.

43
New cards

SymPy

a python library for symbolic mathematics. Made to work with mathematical expressions symbolically rather than numerically, meaning it can perform algebraic manipulations and calculus operations.

44
New cards

Symbolic differentiation and integration with SymPy

refers to the process of computing the derivative function symbolically, providing an exact expression for the rate of change of the function.

45
New cards

Numerical differentiation

refers to the methods for estimating the derivative of a function based on discrete data points. Unlike symbolic differentiation, numerical differentiation uses approximation techniques to estimate derivates when you don't have the symbolic expression but only numerical data of a function at specific points.

46
New cards

Forward difference for numerical differentiation

a method used to approximate the derivative of a function using numerical techniques. This method is particularly used when you don't have the explicit derivative of a function but need to estimate it based on discrete points or numerical data.

47
New cards

Forward difference (Key points)

Step size- the step size (h) should be small to improve accuracy, but if it's too small, it can introduce numerical errors due to limited precision in floating point calculations.

One - sided approximation- unlike other methods, the forward difference only looks at values ahead of (x) which makes it less accurate but easy to compute in some situations.

Applications- this method is useful in scenarios where you have a function represented by discrete data points or when computing derivatives symbolically is difficult.

48
New cards

Backward difference for numerical differentiation

a numerical method used to approximate the derivative of a function. This method is especially useful when you have discrete data points and need to estimate the derivative at a specific point.

49
New cards

backward difference formula

f'(x) = f(x) - f(x - h) / h

50
New cards

Backward difference concept

In this method, we estimate the slope of a tangent to the curve at point (x) by calculating the slope of the line between (x) and a nearby point (x - h). The smaller the value of (h) the close the line between (x) and (x - h) will be to the actual tangent, improving the accuracy of the approximation.

51
New cards

Backward difference (key points)

Step size (h)- the step size should be small to enhance accuracy. However, if it is too small it can cause numerical errors.

One - sided approximation- unlike other methods, the backward difference only uses data points behind (x), which makes it straightforward to compute but potentially less accurate.

Applications- this method is useful when dealing with time series data or when the function values are known only at discrete points and you need to estimate the derivative using past values.

52
New cards

Numerical Integration

refers to techniques used to approximate the integral of a function when an exact analytical solution is difficult or impossible to obtain. It involves using numerical methods to estimate the value of definite integrals.

53
New cards

Trapezoid method for numerical integration

a numerical technique used to approximate the definite integral of a function. It works by approximating the area under the curve as a series of trapezoids, rather than as a series of rectangles.