Advanced Engineering Mathematics
Advanced Engineering Mathematics
10th Edition
ISBN: 9780470458365
Author: Erwin Kreyszig
Publisher: Wiley, John & Sons, Incorporated
Bartleby Related Questions Icon

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 differential equations, but command line 7 defining the system -- [z,p]=y --- gives me the error: too many values to unpack (expected 2) 

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()
expand button
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()
SAVE
AI-Generated Solution
AI-generated content may present inaccurate or offensive content that does not represent bartleby’s views.
bartleby
Unlock instant AI solutions
Tap the button
to generate a solution
Click the button to generate
a solution
Knowledge Booster
Background pattern image
Recommended textbooks for you
Text book image
Advanced Engineering Mathematics
Advanced Math
ISBN:9780470458365
Author:Erwin Kreyszig
Publisher:Wiley, John & Sons, Incorporated
Text book image
Numerical Methods for Engineers
Advanced Math
ISBN:9780073397924
Author:Steven C. Chapra Dr., Raymond P. Canale
Publisher:McGraw-Hill Education
Text book image
Introductory Mathematics for Engineering Applicat...
Advanced Math
ISBN:9781118141809
Author:Nathan Klingbeil
Publisher:WILEY
Text book image
Mathematics For Machine Technology
Advanced Math
ISBN:9781337798310
Author:Peterson, John.
Publisher:Cengage Learning,
Text book image
Basic Technical Mathematics
Advanced Math
ISBN:9780134437705
Author:Washington
Publisher:PEARSON
Text book image
Topology
Advanced Math
ISBN:9780134689517
Author:Munkres, James R.
Publisher:Pearson,