def test_vector_array(): A = [[1.0, 0.0, 2.44]] checkanswer.vector(A, 'be281882fcabe04f0c880b70169814cd')
def test_vector_array(): A = sym.Matrix([1.0, 0.0, 2.44]) checkanswer.vector(A, 'be281882fcabe04f0c880b70169814cd')
# <a name='built-in'></a> # ### The built-in equation solver. # # The function ``np.linalg.solve`` works very well to come up to solutions to a system of equations given in matrix format, $Ax = b$. However, there is the caveat that it only works when the matrix $A$ is square. # # ✅ **<font color=red>QUESTION:</font>** Solve the above system of equations using the ```np.linalg.solve``` function and store the value in a vector named ``x``: # In[ ]: # Put your code to the above question here # In[ ]: from answercheck import checkanswer checkanswer.vector(x, 'fc02fe6d0577c4452ee70252e1e17654') # <a name='inverse'></a> # ### Using the inverse matrix. # # When we know that the square matrix $A$ has an inverse matrix $A^{-1}$, then solving $Ax=b$ is simple, just multiply both sides of the equation by $A^{-1}$ and you get: # # $$A^{-1}Ax = A^{-1}b$$ # # If we apply the definition of the inverse matrix from above we can reduce the equation to: # # $$Ix = A^{-1}b$$ # # We know $I$ times $x$ is just $x$ (definition of the identity matrix), so this further reduces to: # # $$x = A^{-1}b$$
def test_vector_roundoff(): A = np.matrix([[1.000001, 0.00000, 2.440000000234]]) checkanswer.vector(A, 'be281882fcabe04f0c880b70169814cd')
def test_vector_negative_zero(): A = np.matrix([1.0, -0.0, 2.44]) checkanswer.vector(A, 'adc7e01b8bd1778081f6ee348b5eac8c')
def test_vector_float_error(): A = np.matrix([[3.0, 0.0, 0.0, 10.0]]) with pytest.raises(Exception) as e_info: checkanswer.vector(f, '943d90b283d21136da008160e002a5ce')
def test_vector_int(): A = [1.0, 0.0, 2.0] checkanswer.vector(A, '6601896bef296de2c6ea0ca62335dc98') A = [1, 0, 2] checkanswer.vector(A, '6601896bef296de2c6ea0ca62335dc98')
#Test your function here s = 3 v = [3,-7,10] sv_multiply(s,v) # Let us use the following code to test your functon further. # In[ ]: from answercheck import checkanswer checkanswer.detailedwarnings = False checkanswer.vector(sv_multiply(10,[1,2,3,4]),'414a6fea724cafda66ab5971f542adf2') # In[ ]: from answercheck import checkanswer checkanswer.detailedwarnings = False checkanswer.vector(sv_multiply(3.14159,(1,2,3,4)),'f349ef7cafae77c7c23d6924ec1fd36e') # **Note that scalar multiplication and addition works exactly the same way for matrices.** # --- # <a name="linear_combs"></a> # ## 6. Linear Combinations of vectors
def test_vector_array(): A = [[1.0, 0.0, 2.44]] checkanswer.vector(A, 'adc7e01b8bd1778081f6ee348b5eac8c')
def test_vector_transpose(): A = [[1.0], [0.0], [2.44]] checkanswer.vector(A, 'adc7e01b8bd1778081f6ee348b5eac8c')
def test_vector_roundoff(): A = np.matrix([[1.000001, 0.00000, 2.440000234]]) checkanswer.vector(A, 'adc7e01b8bd1778081f6ee348b5eac8c')
# # Find the coordinate vector of $u=(1,-4,-5)$ relative to the given basis $S$. Store this coordinate in a variable ```ub``` for checking. # # In[1]: ##work here import numpy as np # In[2]: from answercheck import checkanswer checkanswer.vector(ub,"91cc7b39126e04b42501804cc9ef7d83"); # ✅ **<font color=red>QUESTION:</font>** Given two bases $S$ and $S'$ in $\mathbb{R}^3$, # $$S = \{(2,-1,-1), (0,1,3), (1,1,1)\},$$ # $$S' = \{(1,4,7), (2,5,8), (3,6,10)\},$$ # Find the transition matrix $T$ that will take points in the $S$ coordinate representation and put them into $S'$ coordinates. # In[ ]: ##work here import numpy as np # In[ ]:
from answercheck import checkanswer checkanswer.matrix(rref, 'cde432847c1c4b6d17cd7bfacc457ed1') # ## The system of equations $Ax = b$ has a unique solution. # # Let us assume some arbitrary vector $b \in R^n$. According to the above properties it should only have one solution. # # ✅ **<font color=red>DO THIS:</font>** Find the solution to $Ax=b$ for the vector $b=(-10,200,3)$. Store the solution in a variable called ```x``` # In[ ]: from answercheck import checkanswer checkanswer.vector(x, '161cfd16545b1b5fb13e35d2800f13df') # ### $rank(A) = n$ # # The final property says that the rank should equal the dimension of $R^n$. In our example $n=3$. Find a ```python``` function to calculate the rank of $A$. Store the value in a variable named ```rank``` to check your answer. # # In[ ]: #Put your answer to the above quesion here # In[ ]: #Verify that the determinate is in fact zero if np.isclose(rank, 3): print("Rank is 3")
def test_vector_transpose(): A = [[1.0], [0.0], [2.44]] checkanswer.vector(A, 'be281882fcabe04f0c880b70169814cd')
def test_vector_sympy(): A = sym.Matrix([[1.0, 0.0, 2.0]]) checkanswer.vector(A, '6601896bef296de2c6ea0ca62335dc98')
def test_vector_negative_zero(): A = np.matrix([1.0, -0.0, 2.44]) checkanswer.vector(A, 'be281882fcabe04f0c880b70169814cd')
checkanswer.matrix(P,'1001a6fa07727caf8ce05226b765542c'); # ✅**<font color=red>QUESTION:</font>** Let's assume that the system starts with; 6 cats in room 1, 15 cats in room 2, and 3 cats in room 3. How many cats will be in each room after one time step (Store the values in a vector called ```current_state```)? # In[ ]: #Put your answer to the above question here. # In[ ]: from answercheck import checkanswer checkanswer.vector(current_state,'98d5519be82a0585654de5eda3a7f397'); # ✅**<font color=red>QUESTION:</font>** The following code will plot the number of cats as a function of time ($t$). When this system converges, what is the steady state? # In[ ]: #Define Start State room1 = [6] room2 = [15] room3 = [3] current_state = np.matrix([room1, room2, room3]) for i in range(10):