Question: I have been trying to execute this code but it won't produce any output no matter what. I need to get the figures I am

I have been trying to execute this code but it won't produce any output no matter what. I need to get the figures I am trying to show down here:
import numpy as np
from scipy.integrate import solve_ivp
import matplotlib.pyplot as plt
# Parameters
sigma =10
r =28
b =8/3
# Lorenz system
def lorenz(t, state, reverse=False):
x, y, z = state
dxdt = sigma *(y - x)
dydt = x *(r - z)- y
dzdt = x * y - b * z
return [-dxdt,-dydt,-dzdt] if reverse else [dxdt, dydt, dzdt]
# Initial conditions for the unstable manifold of the origin
initial_conditions_o =[0.01,0.01,0.01] # Small perturbation
# Initial conditions for the stable manifolds
initial_conditions_c_plus =[np.sqrt(b *(r -1))+0.01, np.sqrt(b *(r -1))+0.01, r -1] initial_conditions_c_minus =[-np.sqrt(b *(r -1))+0.01,-np.sqrt(b *(r -1))+0.01, r -1]
# Time span for integration t_span =(0,50) t_eval = np.linspace(t_span[0], t_span[1],10000)
# Solve the system for the unstable manifold of the origin
solution_o = solve_ivp(lorenz, t_span, initial_conditions_o, t_eval=t_eval, method='RK45') # Solve the system for the stable manifold of C+(reverse time) solution_c_plus = solve_ivp(lorenz, t_span, initial_conditions_c_plus, t_eval=t_eval, method='RK45', args=(True,))
# Solve the system for the stable manifold of C-(reverse time)
solution_c_minus = solve_ivp(lorenz, t_span, initial_conditions_c_minus, t_eval=t_eval, method='RK45', args=(True,))
# Plot the results fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot(solution_o.y[0], solution_o.y[1], solution_o.y[2], label='Unstable Manifold of O')
ax.plot(solution_c_plus.y[0], solution_c_plus.y[1], solution_c_plus.y[2], label='Stable Manifold of C+')
ax.plot(solution_c_minus.y[0], solution_c_minus.y[1], solution_c_minus.y[2], label='Stable Manifold of C-')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
plt.title('Manifolds in the Lorenz System')
plt.legend()
plt.show()```
import numpy as np
from scipy.integrate import solve_ivp
import matplotlib.pyplot as plt
# Parameters
sigma =10
r =28
b =8/3
# Lorenz system
def lorenz(t, state, reverse=False):
x, y, z = state
dxdt = sigma *(y - x)
dydt = x*(r-z)- y
dzdt = x*y - b*z
return [-dxdt,-dydt,-dzdt] if reverse else [dxdt, dydt, dzdt]
# Initial conditions for the unstable manifold of the origin
initial_conditions_0=[0.01,0.01,0.01] # Small perturbation
# Initial conditions for the stable manifolds
initial_conditions_c_plus =[np.sqrt(b *(r -1))+0.01, np.sqrt(b *(r -1))+0.01, r -1]
initial_conditions_c_minus =[-np.sqrt(b *(r -1))+0.01,-np.sqrt(b *(r -1))+0.01, r -1]
# Time span for integration
t_span =(0,20)
t_eval = np.linspace(t_span[0], t_span[1],5000)
# Solve the system for the unstable manifold of the origin
solution_0= solve_ivp(lorenz, t_span, initial_conditions_o, t_eval=t_eval, method='RK45')
# Solve the system for the stable manifold of C+(reverse time)
solution_c_plus = solve_ivp(lorenz, t_span, initial_conditions_c_plus, t_eval=t_eval, method='RK45', args=(True,))
# Solve the system for the stable manifold of C-(reverse time)
solution_c_minus = solve_ivp(lorenz, t_span, initial_conditions_c_minus, t_eval=t_eval, method='RK45', args=(True,))
# Plot the results
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot(solution_o.y[0], solution_o.y[1], solution_o.y[2], label='Unstable Manifold of 0')
ax.plot(solution_c_plus.y[0], solution_c_plus.y[1], solution_c_plus.y[2], label='stable Manifold of C+')
ax.plot(solution_c_minus.y[0], solution_c_minus.y[1], solution_c_minus.y[2], label='stable Manifold of C-')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
plt.title('Manifolds in the Lorenz System')
plt.legend()
plt.show()
```
I have been trying to execute this code but it

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!