Ordinary differential equations: Slope field and solution curves with Matlab
Drawing a slope field with integral curves [MATLAB worked-out solution]
We consider the differential equation
Assignments
- Determine the general solution of the differential equation in implicit form by the method of separation of variables.
- Draw a slope field and use the
contour
function to draw some integral curves in it.
Worked-out solution
- We write the differential equation in differential form and apply separation of variables: When we integrate on both sides we get So: for some constant . In other words, where
- You are asked to draw a slope field and some integral curves in one diagram. The last aspect concerns the drawing of contours of The following code produces the diagram below:
>> clear
>> [t,y] = meshgrid(-3:0.5:7, -4:0.5:4); >> dy = (4-2*t)./(3*y.^2-5); >> dt = ones(size(dy)); >> L = sqrt(dt.^2 + dy.^2); >> dyu = dy./L; >> dtu = dt./L; >> figure
>> % drawing the slope field >> quiver(t, y, dtu, dyu, 0.3, 'r'), axis tight
>> xlabel 't', ylabel 'y'; >> hold on % continue drawing in the same window
>> % Draw integral curves in blue >> [t,y] = meshgrid(-3:0.1:7, -4:0.1:4); >> contour(t,y, y.^3 - 5*y + t.^2 - 4*t, [-8,-4, 0, 4, 8], 'b');
The integral curves describe more than one solution curve. The outer integral curve does this for 3 solution curves that depend on an initial value. We distinguish as solution curves
- the top part with values greater than ;
- the middle part with values between and ;
- the lower part smaller than
Unlock full access