% using y-values from y_min to t_max with spacing of y_spacingįunction dirplotter(f,tval,yval) % plots direction field using aboved defined (f,tval,yval) % using t-values from t_min to t_max with spacing of t_spacing % mathematical expression y in terms of tĭirplotter(f, -1.2:3, -2.2:2) % dirfield(f, t_min:t_spacing:t_max, y_min:y_spacing:y_min) % plot direction field for first order ODE y' = f(t,y) The following Octave code shows how to plot the direction field for the linear differential equation \( y' = 5\,y - 3\,x. Since matlab has no friendly subroutine to plot direction filedsįor ODEs, we present several codes that allow to plot these fields directly. You can grab its modification that works from dfield.m M-functions are not compatible with the latest matlab version. The latest versions of dfield8 and pplane8 It will also find equilibrium points and plot separatrices. It allows the user to plot solution curves in the phase plane, and it also enables a variety of time plots of the Pplane8 plots vector fields for planar autonomous systems. The best way to plot direction fileds is to use existing m-files, credited to John Polking from Rice Universityĭfield8 plots direction fields for single, first order ordinaryĭifferential equations, and allows the user to plot solution curves The following program utilizes the built-in command quiver(x,y,dx,dy) that plots an n × n array of vectors with x- and y- components specified by the n×n matrices d x and d y, based at the xy-points in the plane whose x- and y-coordinates are specified by the n×n matrices x and y. 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. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |