Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
restrepo
GitHub Repository: restrepo/ComputationalMethods
Path: blob/master/material/Taller_algebra_lineal_doe.ipynb
934 views
Kernel: Python 3

Taller álgebra lineal y ecuaciones diferenciales

  1. Encuentre los atovalores y las matrices de diagonalización, tanto con numpy como con scipy

%pylab inline
Populating the interactive namespace from numpy and matplotlib
from scipy import linalg import numpy as np
M=np.array([[1,3,8], [4,3,2], [1,5,3]])
λ2,V=np.linalg.eig(np.dot(M,M.transpose())) #V
λ2,UU=np.linalg.eig( np.dot(M.transpose(),M) ) #U

El reordenamiento tambien funciona con VV

U=np.hstack( [ np.reshape( UU[:,0],(3,1) ), np.reshape( UU[:,2],(3,1) ), np.reshape( UU[:,1],(3,1) )] )
np.dot( np.dot( V.transpose(),M),U).round(13)
array([[-10.75165105, -0. , -0. ], [ -0. , 4.08488967, 0. ], [ 0. , 0. , 2.39074803]])
np.sqrt(λ2)
array([ 10.75165105, 2.39074803, 4.08488967])
linalg.eig( M,left=True,right=True)
(array([ 9.67292784+0.j , -1.33646392+3.01146182j, -1.33646392-3.01146182j]), array([[-0.37851909+0.j , -0.30833931-0.37484143j, -0.30833931+0.37484143j], [-0.65796679+0.j , -0.27614708+0.45108888j, -0.27614708-0.45108888j], [-0.65100154+0.j , 0.69619134+0.j , 0.69619134-0.j ]]), array([[-0.66121269+0.j , -0.71966834+0.j , -0.71966834-0.j ], [-0.54944805+0.j , 0.32760757+0.42615544j, 0.32760757-0.42615544j], [-0.51078823+0.j , 0.08733205-0.43071501j, 0.08733205+0.43071501j]]))
np.abs(λ)
array([ 9.67292784, 3.29469848, 3.29469848])
λ[0]
(9.6729278368191807+0j)
  1. Solucione y gráfique la solución de dxdt=6ydydt=(2t3x)/4y\begin{align} \frac{dx}{dt}=&6y\\ \frac{dy}{dt}=&(2t-3x)/4y \end{align} with x0=1x_0=1 and y0=2y_0=2.

x0,y0=[1,2]
x0
1
y0
2
def dU_dt(U,t): x,y=U return [6*y, (2*t-3*x)/(4.*y)]
import scipy.integrate as integrate
tmax=0.642 t=np.linspace(0.,tmax,100) U=integrate.odeint(dU_dt,[x0,y0],t) plt.plot( t,U[:,0] ) plt.plot( t,U[:,1] )
[<matplotlib.lines.Line2D at 0x7f6c60e6d978>]
Image in a Jupyter notebook
t=np.linspace(0.34,1,100) U=integrate.odeint(dU_dt,[1,2],t)
plt.plot( t,U[:,0] )
[<matplotlib.lines.Line2D at 0x7f6c61e3ff60>]
Image in a Jupyter notebook
  1. Encuentre el espacio de fase de un resorte de constante elástica k=0.1k=0.1 N/m con una masa en el extremo de 0.10.1 Kg.

  1. Implemente la solución de aquú