DGS Studio

Differential Equations

Slope Fields and Solution Curves

Draw slope_field(x-y) as dy/dx = x-y, or plot a dsolve solution. C1 and C2 sliders redraw a general solution, and a click starts a numerical trajectory.

Generate Graph draws slope_field(x-y) as the direction field dy/dx = x-y. Each segment has the same length, so a steep slope stays steep without a long stroke. The grid uses fewer segments when the view is wide and more segments when you zoom in. A vertical tangent is a short vertical stroke, and an undefined slope is skipped. Clicking a point starts an adaptive Runge-Kutta trajectory that stops at a failed step.

The same card also plots dsolve(diff(y(x),x)-y(x),y(x)), the direct integral dsolve(diff(y(x),x)-2*x,y(x)), the oscillator dsolve(diff(y(x),x,2)+y(x),y(x)), and the initial-value solution dsolve(diff(y(x),x)-y(x),y(x),ics={y(0):2}). C1 and C2 sliders redraw a general solution on the board. An initial condition locks those constants. Zoom, pan, and the existing graph export remain available.

Equation

slope_field(x-y)

Graph preview

Graph preview of slope_field(x-y)
A static sample of this expression. The studio draws the full interactive result.

How a differential equation is solved

A first-order equation asks for a function whose slope equals a given expression. When the right-hand side does not depend on the unknown, separation writes dy = g(x) dx and integrates both sides. When it factors as g(x) times h(y), the same separation divides by h(y). An equilibrium y = constant is mentioned only after substitution shows that constant has slope zero. A first-order linear equation multiplies by the integrating factor exp of the integral of P, which turns the left side into the derivative of a product. Those integrals come from the existing antiderivative routine. A method that does not evaluate is not presented as a derivation.

A second-order linear equation with constant coefficients uses its characteristic polynomial. Distinct real roots give two exponential terms. A repeated root multiplies the second term by x. A complex pair gives an exponential times sine and cosine. Initial conditions replace C1 and C2 only after the general solution is formed and checked by substitution. When no closed form is verified, an adaptive Runge-Kutta method samples a trajectory from the given initial value and stops at a failed step instead of drawing across a singularity. A slope field draws a short segment in the direction (1, f) at each grid point, with equal lengths, and a click starts a numerical trajectory from that point.

Reading the input

Other versions of this example

These stay on this page so each version keeps the same explanation. Choose Try example to run a version in its Studio workflow, or copy it into the editable field below.

Slope field

Short segments show dy/dx = x-y. Lengths are normalized, and a click integrates a trajectory.

slope_field(x-y)

Exponential family

The general solution is y(x)=C1*exp(x). The C1 slider redraws it on the slope field.

dsolve(diff(y(x),x)-y(x),y(x))

Direct integration

The general solution is y(x)=x^2+C1.

dsolve(diff(y(x),x)-2*x,y(x))

Harmonic oscillator

The general solution is y(x)=C1*cos(x)+C2*sin(x). Both constants have sliders.

dsolve(diff(y(x),x,2)+y(x),y(x))

Growth rate 2

The general solution is y(x)=C1*exp(2*x).

dsolve(diff(y(x),x)-2*y(x),y(x))

Gaussian factor

The general solution is y(x)=C1*exp(x^2/2).

dsolve(diff(y(x),x)-x*y(x),y(x))

Initial value

y(0)=2 selects y(x)=2*exp(x). The constants are no longer free.

dsolve(diff(y(x),x)-y(x),y(x),ics={y(0):2})

Try a change

Generate Graph draws a first-order slope field with equal-length segments, plots a verified solution, and keeps C1 and C2 sliders when the general solution still contains them. Zoom, pan, and export stay on the board. A click integrates a numerical trajectory and does not join it across a failed step.

Edit and generate

Generate Graph opens the studio homepage and runs this field. Open in DGS Studio loads the same text and waits for you to generate it. The equation is sent once, as a query parameter.

Related examples