# You must make sure to run all cells in sequence using shift + enter or you might encounter errors
from pykubegrader.initialize import initialize_assignment
responses = initialize_assignment("1_practicequiz_q", "week_8", "practicequiz", assignment_points = 12.0, assignment_tag = 'week8-practicequiz')
# Initialize Otter
import otter
grader = otter.Notebook("1_practicequiz_q.ipynb")
โQuiz: Implicit Equation Plotting#
๐ Mathematical Equations#
\[
\text{eq1:} \quad \left(\frac{x}{7}\right)^2 \sqrt{\frac{\left| |x| - 3 \right|}{|x| - 3}} + \left(\frac{y}{3}\right)^2 \sqrt{\frac{\left| y + \frac{3}{7}\sqrt{33} \right|}{y + \frac{3}{7}\sqrt{33}}} - 1
\]
\[
\text{eq2:} \quad \left| \frac{x}{2} \right| - \frac{3\sqrt{33} - 7}{112}x^2 - 3 + \sqrt{1 - \left(| |x| - 2 | - 1\right)^2} - y
\]
\[
\text{eq3:} \quad 9\sqrt{\frac{\left| (|x| - 1)(|x| - 0.75) \right|}{(1 - |x|)(|x| - 0.75)}} - 8|x| - y
\]
import warnings
warnings.filterwarnings('ignore')
# Importing the necessary libraries
# The following libraries are used in the code below
# import sqrt, meshgrid, arange from numpy
# pyplot from matplotlib as plt
# division from __future__ to make sure that the division is float division
# The code below is written in Python 3
...
# Define the grid range
xs = arange(-7.25, 7.25, 0.01)
ys = arange(-5, 5, 0.01)
x, y = meshgrid(xs, ys)
# Predefine the equations
eq4 = (3 * abs(x) + 0.75 * sqrt(abs((abs(x) - 0.75) * (abs(x) - 0.5)) / ((0.75 - abs(x)) * (abs(x) - 0.5))) - y)
eq5 = (2.25 * sqrt(abs((x - 0.5) * (x + 0.5)) / ((0.5 - x) * (0.5 + x))) - y)
eq6 = (6 * sqrt(10) / 7 + (1.5 - 0.5 * abs(x)) * sqrt(abs(abs(x) - 1) / (abs(x) - 1)) - (6 * sqrt(10) / 14) * sqrt(4 - (abs(x) - 1)**2) - y)
grader.check("q1-import-libraries")
Question 1 (Points: 2.0): ๐ Mathematical Equations#
Computing the first equation#
\[
\text{eq1:} \quad \left(\frac{x}{7}\right)^2 \sqrt{\frac{\left| |x| - 3 \right|}{|x| - 3}} + \left(\frac{y}{3}\right)^2 \sqrt{\frac{\left| y + \frac{3}{7}\sqrt{33} \right|}{y + \frac{3}{7}\sqrt{33}}} - 1
\]
# Define the function to compute the equation 1 as compute_equation_1 with x and y as parameters
# The function should return the equation 1 as eq1
...
"""Compute the equation for contour plotting."""
...
# Return the equation 1 as eq1
...
# List of equations to plot
# Compute the equation 1 as plot_equation_1
...
# List of equations to plot as plot_equations, include plot_equation_1, eq4, eq5, eq6
...
# Generate contour plots for the equations as eq in plot_equations using plt.contour
# The contour should be generated for x, y and eq with the level set to 0
# you should use a for loop to iterate over the plot_equations, contour takes 3 arguments x, y and eq, and the level is 0
# for example plt.contour(x, y, eq, [0])
...
grader.check("q2-compute-the-first-equation")
Question 2 (Points: 2.0): Compute for equation 2#
\[
\text{eq2:} \quad \left| \frac{x}{2} \right| - \frac{3\sqrt{33} - 7}{112}x^2 - 3 + \sqrt{1 - \left(| |x| - 2 | - 1\right)^2} - y
\]
# Define the function to compute the equation 2 as compute_equation_2 with x and y as parameters
# The function should return the equation 2 as eq2
...
"""Compute the equation for contour plotting."""
...
# Return the equation 2 as eq2
...
# Compute the equation 2 as plot_equation_2
...
# List of equations to plot as plot_equations with plot_equation_1 and plot_equation_2 , eq4, eq5, eq6
...
# Generate contour plots for the equations as eq in plot_equations using plt.contour
# The contour should be generated for x, y and eq with the level set to 0
# hint: you can use the same for loop as in the previous question
...
grader.check("q3-compute-the-second-equation")
Question 4 (Points: 6.0): Question 3 (Points: 2.0): Compute Equation 3#
\[
\text{eq3:} \quad 9\sqrt{\frac{\left| (|x| - 1)(|x| - 0.75) \right|}{(1 - |x|)(|x| - 0.75)}} - 8|x| - y
\]
# Define the function to compute the equation 3 as compute_equation_3 with x and y as parameters
# The function should return the equation 3 as eq3
...
"""Compute the equation for contour plotting."""
...
# Return the equation 3 as eq3
...
# Compute the equation 3 as plot_equation_3
...
# List of equations to plot as plot_equations with plot_equation_1, plot_equation_2 and plot_equation_3
...
# Generate contour plots for the equations as eq in plot_equations using plt.contour
# The contour should be generated for x, y and eq with the level set to 0
...
grader.check("q4-compute-the-third-equation")
Submitting Assignment#
Please run the following block of code using shift + enter
to submit your assignment, you should see your score.
from pykubegrader.submit.submit_assignment import submit_assignment
submit_assignment("week8-practicequiz", "1_practicequiz_q")