
Ashley P.
asked 05/29/23MATLAB Plot of Solutions and Directional Field
I'm trying to plot solutions along with the directional field as in the image given below, of the constant harvesting model given by
dP/dt = r*P(1 - (P/M)) - h , P(0) =p0 , where r = 0.8, M = 8000 and h = 0 in this particular case.
I attempted using the following code, which does not result in something as in the image 1. I would appreciate your help with making the graph looks like as in the image 1.
Image 1(Required graph): drive[DOT]google.com/file/d/1WPREaQrGLi_cGrXevtN5ajMq1QR4acGI/view?usp=sharing
Image 2(The result I got with my code): drive.google[DOT]com/file/d/1QkDFIsTO0UzZfRCpBhfZtiPnpqlWPxL0/view?usp=sharing
I'm using MATLAB online free version
1 Expert Answer
Joseph B. answered 08/02/25
B.S. Computer Engineering | Robotics Lead and Research Assistant
SET parameters r = 0.8, M = 8000, h = 0
DEFINE time range t from 0 to 20
DEFINE population range P from 0 to 9000
CREATE a grid of points (T, Pgrid) using meshgrid over t and P
FOR each point in the grid:
COMPUTE slope dPdt = r * Pgrid * (1 - Pgrid/M) - h
NORMALIZE slopes:
SET dt = 1 for all points
COMPUTE magnitude = sqrt(dt^2 + dPdt^2)
DIVIDE dt and dPdt by magnitude
PLOT the slope field using quiver(T, Pgrid, dt, dPdt)
FOR each initial population value p0 in [100, 1000, 4000, 7000, 8500]:
SOLVE the ODE dP/dt = r*P*(1 - P/M) - h from t=0 to t=20 using ode solver
PLOT the solution curve
LABEL axes and add title
DISPLAY gridlines
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Rory M.
It looks like your code ( following code ) section is missing.02/20/24