Question: For the differential equation x ' = 7 x ( 1 x ) ( x 2 ) x , Plot the direction field and superimpose

For the differential equation
x'=7x(1x)(x2)x,
Plot the direction field and superimpose 4 solutions on the plots. Use the following five initial conditions to obtain these solutions:
x0=0.9,x0=1.2, x0=3 and x0=2.5
Notes:
Please do not modify the already provided code in the cell below
In the code cell follow the 6 steps outlined below
Step 1: define a Python function to encode the right hand side of the ODE
Step 2: define the ODE vector field
Step 3: normalize the vector field arrows
Step 4: plot the direction fields
Step 5: numerically solve the ODE. Each solution corresponds to an Initial Value Problem (IVP), which consists of the ordinary differential equation and the initial condition. In the cell code below you are asked to use the five initial conditions specified above. These give rise to 4 solution curves superimposed on the direction field
Step 6: set graph x and y limits, labels and title.
Use code simular to this provided example:
# MAIN CODE CELL FOR PROBLEM 3
fig = plt.figure()
# Step 1. Define the right-hand side of the ODE (note the different order)
def vf(x, t):
dx = np.zeros(1)
dx[0]=1/(t**2+x[0]**2) # dx[0] will change with each problem
return dx
# Step 2. Vector field
tgrid=np.linspace(-3,5,12)
xgrid=np.linspace(-3,3,12)
T, X = np.meshgrid(tgrid,xgrid)
U =1.0
V =1/(T**2+ X**2) # this is the RHS of the ODE. It will change with each problem
# Step 3. Normalize arrows
N = np.sqrt(U **2+ V **2)
U = U / N
V = V / N
# Step 4. Use "plt.quiver()" to plot the direction fields
plt.quiver(T, X, U, V, angles="xy", scale_units='xy', scale=7, headlength=0,headwidth=1,color='red')
# Step 5. Numerically solve the ODE for various initial conditions (see below "for x0 in ...")
t0=-3.0
tEnd =5.0
t = np.linspace(t0, tEnd, 100)
for x0 in [-3.0,-1.5,2.5]: # you can try other values for x0
x_initial =[x0]
x = integrate.odeint(vf,x_initial, t)
plt.plot(t, x[:,0],"-")
# Step 6. Set the plot xlim, ylim, labels and title.
plt.xlim([-3,5])
plt.ylim([-3,3])
plt.xlabel('t')
plt.ylabel('x')
figTitle = "Direction fields and solution curves for $1/(t^2+x^2)$"
plt.title(figTitle)
plt.show()

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 Databases Questions!