Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems 6th Asian Conference Aciids 2014 Bangkok Thailand April 7 9 2014 Proceedings Part I 9 2014 Proceedings Part 1 Lnai 8397

Authors: Ngoc-Thanh Nguyen ,Boonwat Attachoo ,Bogdan Trawinski ,Kulwadee Somboonviwat

2014th Edition

3319054759, 978-3319054759

More Books

Students also viewed these Databases questions