import numpy as np import matplotlib. pyplot as plt from scipy. integrate import odeint # Define the system of differential equations def system(y, t): [z,p] = y dzdt= 2 * z - z* *2- z*p dpdt = p**2 p * (z**2) return [dzdt, dpdt] # Function to calculate the Jacobian matrix at an equilibrium point def jacobian_matrix (point): z, p = point return np.array ( [ [2 - 2+ z-p, -z], [-2 pz, 2 p - z**2]]) # Equilibrium points equilibrium_points = [(0, 0), (1, 1), (2, 0), (-2, 4)] # Set up the plot fig, axs plt.subplots (2, 2, figsize=(10, 8)) fig.suptitle('Phase Portraits for Linearized Solutions') # Plot linearized solutions at each equilibrium point for i, point in enumerate(equilibrium_points): # Calculate the Jacobian matrix at the equilibrium point A = jacobian_matrix (point) # Eigenvalues and eigenvectors eigenvalues, eigenvectors = np. linalg.eig (A) # Initial conditions for the linearized system ye = np.concatenate ([point, eigenvectors[:, 0]]) # Time points t = np. linspace(0, 5, 100) # Solve the linearized system linearized_solution = odeint (system, ye, t) #Plot the phase portrait axs[i // 2, 1 % 2].plot(linearized_solution[:, 0], linearized_solution[:, 1]) axs [i // 2, 1 % 2].set_title(f'Equilibrium Point: {point}') #Set common labels for ax in axs.flat: ax.set (xlabel='z', ylabel='p') # Adjust layout plt.tight_layout(rect= [0, 0.03, 1, 0.95]) # Show the plot plt.show()
import numpy as np import matplotlib. pyplot as plt from scipy. integrate import odeint # Define the system of differential equations def system(y, t): [z,p] = y dzdt= 2 * z - z* *2- z*p dpdt = p**2 p * (z**2) return [dzdt, dpdt] # Function to calculate the Jacobian matrix at an equilibrium point def jacobian_matrix (point): z, p = point return np.array ( [ [2 - 2+ z-p, -z], [-2 pz, 2 p - z**2]]) # Equilibrium points equilibrium_points = [(0, 0), (1, 1), (2, 0), (-2, 4)] # Set up the plot fig, axs plt.subplots (2, 2, figsize=(10, 8)) fig.suptitle('Phase Portraits for Linearized Solutions') # Plot linearized solutions at each equilibrium point for i, point in enumerate(equilibrium_points): # Calculate the Jacobian matrix at the equilibrium point A = jacobian_matrix (point) # Eigenvalues and eigenvectors eigenvalues, eigenvectors = np. linalg.eig (A) # Initial conditions for the linearized system ye = np.concatenate ([point, eigenvectors[:, 0]]) # Time points t = np. linspace(0, 5, 100) # Solve the linearized system linearized_solution = odeint (system, ye, t) #Plot the phase portrait axs[i // 2, 1 % 2].plot(linearized_solution[:, 0], linearized_solution[:, 1]) axs [i // 2, 1 % 2].set_title(f'Equilibrium Point: {point}') #Set common labels for ax in axs.flat: ax.set (xlabel='z', ylabel='p') # Adjust layout plt.tight_layout(rect= [0, 0.03, 1, 0.95]) # Show the plot plt.show()
Advanced Engineering Mathematics
10th Edition
ISBN:9780470458365
Author:Erwin Kreyszig
Publisher:Erwin Kreyszig
Chapter2: Second-order Linear Odes
Section: Chapter Questions
Problem 1RQ
Related questions
Question
what is wrong with the python code? Trying to plot phase portraits for the linearized systems for each equilibrium point of a non-linear system of
![import numpy as np
import matplotlib. pyplot as plt
from scipy. integrate import odeint
# Define the system of differential equations
def system(y, t):
[z,p] = y
dzdt= 2 * z - z* *2- z*p
dpdt = p**2 p * (z**2)
return [dzdt, dpdt]
# Function to calculate the Jacobian matrix at an equilibrium point
def jacobian_matrix (point):
z, p = point
return np.array ( [ [2 - 2+ z-p, -z], [-2 pz, 2 p - z**2]])
# Equilibrium points
equilibrium_points = [(0, 0), (1, 1), (2, 0), (-2, 4)]
# Set up the plot
fig, axs
plt.subplots (2, 2, figsize=(10, 8))
fig.suptitle('Phase Portraits for Linearized Solutions')
# Plot linearized solutions at each equilibrium point
for i, point in enumerate(equilibrium_points):
# Calculate the Jacobian matrix at the equilibrium point
A = jacobian_matrix (point)
# Eigenvalues and eigenvectors
eigenvalues, eigenvectors = np. linalg.eig (A)
# Initial conditions for the linearized system
ye = np.concatenate ([point, eigenvectors[:, 0]])
# Time points
t = np. linspace(0, 5, 100)
# Solve the linearized system
linearized_solution = odeint (system, ye, t)
#Plot the phase portrait
axs[i // 2, 1 % 2].plot(linearized_solution[:, 0], linearized_solution[:, 1])
axs [i // 2, 1 % 2].set_title(f'Equilibrium Point: {point}')
#Set common labels
for ax in axs.flat:
ax.set (xlabel='z', ylabel='p')
# Adjust layout
plt.tight_layout(rect= [0, 0.03, 1, 0.95])
# Show the plot
plt.show()](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F6d0ee2cb-cfe2-4eb9-a097-d38324436758%2F31739f29-dcbc-41ae-a40b-3dc84de4a1fe%2Fv2ellz9_processed.jpeg&w=3840&q=75)
Transcribed Image Text:import numpy as np
import matplotlib. pyplot as plt
from scipy. integrate import odeint
# Define the system of differential equations
def system(y, t):
[z,p] = y
dzdt= 2 * z - z* *2- z*p
dpdt = p**2 p * (z**2)
return [dzdt, dpdt]
# Function to calculate the Jacobian matrix at an equilibrium point
def jacobian_matrix (point):
z, p = point
return np.array ( [ [2 - 2+ z-p, -z], [-2 pz, 2 p - z**2]])
# Equilibrium points
equilibrium_points = [(0, 0), (1, 1), (2, 0), (-2, 4)]
# Set up the plot
fig, axs
plt.subplots (2, 2, figsize=(10, 8))
fig.suptitle('Phase Portraits for Linearized Solutions')
# Plot linearized solutions at each equilibrium point
for i, point in enumerate(equilibrium_points):
# Calculate the Jacobian matrix at the equilibrium point
A = jacobian_matrix (point)
# Eigenvalues and eigenvectors
eigenvalues, eigenvectors = np. linalg.eig (A)
# Initial conditions for the linearized system
ye = np.concatenate ([point, eigenvectors[:, 0]])
# Time points
t = np. linspace(0, 5, 100)
# Solve the linearized system
linearized_solution = odeint (system, ye, t)
#Plot the phase portrait
axs[i // 2, 1 % 2].plot(linearized_solution[:, 0], linearized_solution[:, 1])
axs [i // 2, 1 % 2].set_title(f'Equilibrium Point: {point}')
#Set common labels
for ax in axs.flat:
ax.set (xlabel='z', ylabel='p')
# Adjust layout
plt.tight_layout(rect= [0, 0.03, 1, 0.95])
# Show the plot
plt.show()
AI-Generated Solution
Unlock instant AI solutions
Tap the button
to generate a solution
Recommended textbooks for you
![Advanced Engineering Mathematics](https://www.bartleby.com/isbn_cover_images/9780470458365/9780470458365_smallCoverImage.gif)
Advanced Engineering Mathematics
Advanced Math
ISBN:
9780470458365
Author:
Erwin Kreyszig
Publisher:
Wiley, John & Sons, Incorporated
![Numerical Methods for Engineers](https://www.bartleby.com/isbn_cover_images/9780073397924/9780073397924_smallCoverImage.gif)
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…](https://www.bartleby.com/isbn_cover_images/9781118141809/9781118141809_smallCoverImage.gif)
Introductory Mathematics for Engineering Applicat…
Advanced Math
ISBN:
9781118141809
Author:
Nathan Klingbeil
Publisher:
WILEY
![Advanced Engineering Mathematics](https://www.bartleby.com/isbn_cover_images/9780470458365/9780470458365_smallCoverImage.gif)
Advanced Engineering Mathematics
Advanced Math
ISBN:
9780470458365
Author:
Erwin Kreyszig
Publisher:
Wiley, John & Sons, Incorporated
![Numerical Methods for Engineers](https://www.bartleby.com/isbn_cover_images/9780073397924/9780073397924_smallCoverImage.gif)
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…](https://www.bartleby.com/isbn_cover_images/9781118141809/9781118141809_smallCoverImage.gif)
Introductory Mathematics for Engineering Applicat…
Advanced Math
ISBN:
9781118141809
Author:
Nathan Klingbeil
Publisher:
WILEY
![Mathematics For Machine Technology](https://www.bartleby.com/isbn_cover_images/9781337798310/9781337798310_smallCoverImage.jpg)
Mathematics For Machine Technology
Advanced Math
ISBN:
9781337798310
Author:
Peterson, John.
Publisher:
Cengage Learning,
![Basic Technical Mathematics](https://www.bartleby.com/isbn_cover_images/9780134437705/9780134437705_smallCoverImage.gif)
![Topology](https://www.bartleby.com/isbn_cover_images/9780134689517/9780134689517_smallCoverImage.gif)