βŒ›οΈ Quiz 3 - Using Python to Solve Math Problems#

This quiz will explore using python’s capabilities for mathematical calculations.

Instructions#

You will click on the following link to start your quiz. Do not start the quiz before your lab section. We have checks in place to ensure that you do not start the quiz early. If you do, you will receive a 0 on the quiz. Furthermore, it could be considered an academic integrity violation.

CLICK HERE TO START YOUR QUIZ IN LAB

Part 1: Entering Your Information for Credit#

To receive credit for assignments it is important we can identify your work from others. To do this we will ask you to enter your information in the following code block.

Before you begin#

Run the block of code at the top of the notebook that imports and sets up the autograder. This will allow you to check your work.

# Please provide your first name, last name, Drexel ID, and Drexel email. Make sure these are provided as strings. "STRINGS ARE TEXT ENCLOSED IN QUOTATION MARKS."

# In the assignments you will see sections of code that you need to fill in that are marked with ... (three dots). Replace the ... with your code.
first_name = ...
last_name = ...
drexel_id = ...
drexel_email = ...

Question 1: Calculate the voltage across a capacitor

The charging or discharging behavior of a capacitor in a resistor-capacitor circuit is given by

\[ V_{\text{cap}}(t) = V_{\text{supply}} \cdot \left(1 - e^{-\frac{t}{RC}}\right) \]

where \(V(t)\) is the voltage across the capacitor at time \(t\) in seconds, \(V_{\text{supply}}\) is the supply voltage in volts, \(R\) is the resistance in ohms, and \(C\) is the capacitance in farads.

Write python code to do the following:

  • Define variables: V_supply = 12, R = 1000, and C = 0.001.

  • Calculate the voltage across the capacitor at t = 5 seconds based on the equation above.

  • Store the final value in a variable called V_cap.

Note: Your code should be indented under what’s called the function definition: def question_1():. This helps the autograder run all the code you write by calling a single name. (Functions will be taught in future weeks.).

Note: Python cares about Tabs make sure the spacing is correct. If you get an Indention Error it likely means your spacing is not correct.

Your solution should look like this:

def question ():
    line1 = line1_code # line 1 of code
    line2 = line2_code # line 2 of code

    return x, y, z # variables to return separated by commas

Your code replaces the prompt: ...

import numpy as np

# define a function called question_1 to be used for grading
def question_1():

    ...

    # The following line outputs these values from the function so that they can be accessed by the grader
    return t, V_supply, R, C, V_cap

Question 2: Using Python as a calculator

We have seen how Python can be used to evaluate mathematical expressions. This problem provides practice incorporating various mathematical functions and constants.

Write python code to do the following:

  • Define variables: a = 2, b = -7, and x = 3

  • For each of the quantities \(E_0\) through \(E_2\), construct a one-line Python expression that computes the value and assigns it to a variable. (You should perform your computations using the variable names \(a\), \(b\), and \(c\) instead of their numerical values). In Python, we will use variable names E0 through E2 to store the values \(E_0\) through \(E_2\). Definitions of the variables E0 through E2 have been started for you in the template.

\(\text{i. } E_0 = \arcsin(\sin(a))\)

\(\text{ii. } E_1 = \cos(b^2)\)

\(\text{iii. } E_2 = \log_{10} \left(\left|3x\right|\right)\)

You should use the NumPy library for the required mathematical functions. You can discover the necessary functions using the Numpy Documentation

We have used the standard NumPy convention import numpy as np, thus, for example the cos function is used by typing np.cos(<value>)

Again, your code should be indented under the function definition: def question_3():.

Your code replaces the prompt: ...

# import the np library to be used
import numpy as np

# define a function called question_3 to be used for grading
def question_3():

    a = ...
    b = ...
    x = ...

    E0 = ...
    E1 = ...
    E2 = ...

    # output these values from the function so that they can be accessed by the grader
    return a, b, x, E0, E1, E2

Submitting Your Assignment#

To submit your assignment please use the following link the assignment on GitHub classroom.

Use this link to navigate to the assignment on GitHub classroom.

Please submit just your output.log file. No other files are needed.

If you need further instructions on submitting your assignment, please ask your TA during lab.

Viewing your score#

Each log file you have uploaded will have a file with the name of your file + Grade_Report.md. You can view this file by clicking on the file name. This will show you the results of the autograder.

Make sure you run your code, and run the tests. If you do not run the test you will not get credit for your work.

Note

In python and particularly jupyter notebooks it is common that during testing you run cells in a different order, or run cells and modify them. This can cause there to be local variables needed for your solution that would not be recreated on running your code again from scratch. Your assignment will be graded based on running your code from scratch. This means before you submit your assignment you should restart the kernel and run all cells. You can do this by clicking Kernel and selecting Restart and Run All. If you code does not run as expected after restarting the kernel and running all cells it means you have an error in your code.

Fin#