what is wrong with my python code? I am trying to write a code to plot the direction field/phase portrait for a system of linear differential equations. The solution passes through (-2,-2) and the equations are x_1'=2x_1 - x_2 and x_2'=-x_1 + x_2

Advanced Engineering Mathematics
10th Edition
ISBN:9780470458365
Author:Erwin Kreyszig
Publisher:Erwin Kreyszig
Chapter2: Second-order Linear Odes
Section: Chapter Questions
Problem 1RQ
icon
Related questions
Question
100%

what is wrong with my python code? I am trying to write a code to plot the direction field/phase portrait for a system of linear differential equations. The solution passes through (-2,-2) and the equations are x_1'=2x_1 - x_2 and x_2'=-x_1 + x_2

 

import matplotlib.pyplot as plt
from scipy.integrate import odeint
from numpy import linalg as LA
import numpy as np
a=2
b=-1
c=-1
d=1
## Vector field function
def vf(x, t):
x_1prime=a*X[0]+b*X[1]
x_2prime=c*X[0]+d*X[1]
return [x_1prime,x_2prime]
## Solution curves
t0=0; tEnd=10
t=np. linspace(t0,tEnd, 50* (tEnd-to))
x_1_0= [0, -2] #first initial condidion
x_1=odeint (vf,x_0, t)
x_2_0= [0, -2] #second initial condition
x_2=odeint (vf, y02, t)
## Generate the eigen values
B=np.array([[a,b], [c, d]])
u,v=LA.eig (B)
print('eigenvalues and eigenvectors')
print (u)
print (v)
Transcribed Image Text:import matplotlib.pyplot as plt from scipy.integrate import odeint from numpy import linalg as LA import numpy as np a=2 b=-1 c=-1 d=1 ## Vector field function def vf(x, t): x_1prime=a*X[0]+b*X[1] x_2prime=c*X[0]+d*X[1] return [x_1prime,x_2prime] ## Solution curves t0=0; tEnd=10 t=np. linspace(t0,tEnd, 50* (tEnd-to)) x_1_0= [0, -2] #first initial condidion x_1=odeint (vf,x_0, t) x_2_0= [0, -2] #second initial condition x_2=odeint (vf, y02, t) ## Generate the eigen values B=np.array([[a,b], [c, d]]) u,v=LA.eig (B) print('eigenvalues and eigenvectors') print (u) print (v)
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Recommended textbooks for you
Advanced Engineering Mathematics
Advanced Engineering Mathematics
Advanced Math
ISBN:
9780470458365
Author:
Erwin Kreyszig
Publisher:
Wiley, John & Sons, Incorporated
Numerical Methods for Engineers
Numerical Methods for Engineers
Advanced Math
ISBN:
9780073397924
Author:
Steven C. Chapra Dr., Raymond P. Canale
Publisher:
McGraw-Hill Education
Introductory Mathematics for Engineering Applicat…
Introductory Mathematics for Engineering Applicat…
Advanced Math
ISBN:
9781118141809
Author:
Nathan Klingbeil
Publisher:
WILEY
Mathematics For Machine Technology
Mathematics For Machine Technology
Advanced Math
ISBN:
9781337798310
Author:
Peterson, John.
Publisher:
Cengage Learning,
Basic Technical Mathematics
Basic Technical Mathematics
Advanced Math
ISBN:
9780134437705
Author:
Washington
Publisher:
PEARSON
Topology
Topology
Advanced Math
ISBN:
9780134689517
Author:
Munkres, James R.
Publisher:
Pearson,