Ejemplo n.º 1
0
def test_vector_float_error():
    A = np.matrix([[3.0, 0.0, 0.0, 10.0]])
    with pytest.raises(Exception) as e_info:
        checkanswer.eq_vector(f, '943d90b283d21136da008160e002a5ce')
Ejemplo n.º 2
0
def test_vector_sympy():
    A = sym.Matrix([[1.0, 0.0, 2.0]])
    checkanswer.eq_vector(A, '32afcef773e6a61d654a35be8bf14900')
Ejemplo n.º 3
0
def test_vector_int():
    A = [1.0, 0.0, 2.0]
    checkanswer.eq_vector(A, '32afcef773e6a61d654a35be8bf14900')
    A = [1, 0, 2]
    checkanswer.eq_vector(A, '32afcef773e6a61d654a35be8bf14900')
from answercheck import checkanswer
checkanswer.float(e1, "d1bd83a33f1a841ab7fda32449746cc4");


# In[ ]:


from answercheck import checkanswer
checkanswer.float(e2, "e4c2e8edac362acab7123654b9e73432");


# In[ ]:


from answercheck import checkanswer
checkanswer.eq_vector(vec1, "09d9df5806bc8ef975074779da1f1023", decimal_accuracy = 4)


# In[ ]:


from answercheck import checkanswer
checkanswer.eq_vector(vec2, "d28f0a721eedb3d5a4c714744883932e", decimal_accuracy = 4)


# &#9989;  **<font color=red>Question:</font>**
# What relationship do you notice between the values of ``e1``, ``e2``, and the matrix $D$ above?

# Your answer here.

# ### A second example
Ejemplo n.º 5
0
# In[ ]:


# Put your answer here


# &#9989; **<font color=red>QUESTION:</font>** What are the corresponding eigenvectors to the matrix $A$? This time you can try calculating by hand or just used the function you found in the previous answer.  Store the eigenvector associated with the ```e1``` value in a vector named ```v1``` and the eigenvector associated with the eigenvalue ```e2``` in a vector named ```v2``` to check your answer.  

# Put your answer to the above question here.

# In[ ]:


from answercheck import checkanswer

checkanswer.eq_vector(v1,'35758bc2fa8ff4f04cfbcd019844f93d');


# In[ ]:


from answercheck import checkanswer

checkanswer.eq_vector(v2,'90b0437e86d2cf70050d1d6081d942f4');


# ---
# <a name="T3"></a>
# ## 7. Assignment wrap up
# 
# 
Ejemplo n.º 6
0
# The eigenvector associated with the eigenvalue of 1 represents the steady state probability for our original transition matrix $P$.  
# 
# &#9989;**<font color=red>DO THIS:</font>** make a new vector called ```steadystate``` from the eigenvector of your $P$ matrix with a eigenvalue of 1.

# In[ ]:


## Put your answer here


# In[ ]:


from answercheck import checkanswer
checkanswer.detailedwarnings = False
checkanswer.eq_vector(steadystate,'462ea7dca751db590ed09356886ad060')


# Since the ```steadystate``` vectors represent long term probibilities, they should sum to one (1).  However, most programming libraries (ex. numpy and sympy) return "normalized" eigenvectors to length of 1 (i.e. norm(e)==1). 
# 
# &#9989;**<font color=red>DO THIS:</font>**  Correct for the normalization by multiplying the ```steadystate``` eigenvector by a constant such that the sum of the vector elements add to 1. 

# In[ ]:


#Put your answer here


# &#9989;**<font color=red>DO THIS:</font>**  Think about the cats problem, because one cat has to be in one of the three rooms. That means, the total number of cats will not change. If we add the number of cats at all rooms together, this number has to be the same. Therefore, if we start will 6+15+3=24 cats, there are also 24 cats at the ```steadystate```. Modify the steadystate to make sure the total number of cats is 24.

# In[ ]: