Unless the special purposed field program is used, plotting slope fields in matlab requiries a bit of work. This specific curve is called the separatrix. The picture strongly suggests that some solutions approach a specific curve, but others tend to minus infinity. Xlabel('x') ylabel('y') title('Slope field for dy/dx = 5y - 3x') % Below is some code for labeling our graph and adding a title % separatrix by hand and then enter its equation into MATLAB % To also graph the separatrix, use the hold on command, which will add % Use the quiver function to plot slope vectors for the ranges % Using theta, you can split the slope into x and y components (note that % Calculate the angle theta between the slope and the horizontal using the % (as opposed to matrix-matrix multiplication) * instead of * for element-wise matrix multiplication % Next, set up matrix of slope values from the differential equation % Meshgrid sets up the x-coordinate range and y-coordinate range Finally, we plot the separatrix, which needs to be derived by We split the slope into xĪnd y components and normalize it using arctangent, sine, andĬosine, allowing us to plot vectors of magnitude 1 for our directionįield. The result isĬode using trigonometric functions. The fifth entry, 0.5, in the quiver command reduces the length of the vectors by half and prevents the arrow heads from swallowing up the tails of nearby vectors. Title 'Direction field for dy/dx = 1-xy^2' S = 1 - x.*y.^2 % for slope function f = 1 - x y^2 \) In order to achieve it in matlab, we modify the preceeding sequence of commands to: A direction field or a slope field for a first order differential equation \(.
0 Comments
Leave a Reply. |