Slope fields or direction fields, are a graphical representation of the solutions to a first-order differential equation of a scalar function. A slope field shows the slope of a differential equation at certain vertical and horizontal intervals on the cartesian plane, and can be used to determine the approximate tangent slope at a point on a curve, where the curve is some solution to the differential equation. For example consider the differential equation:
$$ \frac{dy}{dx} = \frac{y-4x}{x-y} $$
The corresponding slope field will look like:
Another example with this differential equation:
$$ \frac{dy}{dx} = \frac{x-y}{x-2y} $$
Your task is to generate such slope fields in the console with characters of text. You are to print the following for each coordinate pair:
/
If the differential equation evaluated at the point \$(x, y)\$ is positive.\
If the differential equation evaluated at the point \$(x, y)\$ is negative.-
If the differential equation evaluated at the point \$(x, y) = 0\$.|
If the differential equation evaluated at the point \$(x, y)\$ is undefined.
The inputs are a string and a number consisting of:
- Expression string that can be evaluated (or parsed if you have to).
- A number that outlines the radius of the plot from \$(0, 0)\$.
The expression string can use any built-in mathematical function and will only either \$x\$ or \$y\$ as variables. Any combination of logarithms, (inverse and/or hyperbolic) trigonometric functions, or functions like sqrt(), pow(), exp(), abs()
may be used in the expression. The plot radius may also be 0, which means only print one character containing the slope at the origin. A sample input may look something like:
plotRadius = 10
expression = "(x - y) / (x - 2 * y)"
Notice how both the boundaries of the plot follow: \$ -\text{plotRadius} \leq x, y \leq \text{plotRadius}\$. This results in the following slope field being displayed:
/ / / / / / / / / / / / / / / / / / / / —
/ / / / / / / / / / / / / / / / / / / — \
/ / / / / / / / / / / / / / / / / / — \ \
/ / / / / / / / / / / / / / / / / — \ \ \
/ / / / / / / / / / / / / / / / — \ \ \ \
/ / / / / / / / / / / / / / / — \ \ \ \ |
/ / / / / / / / / / / / / / — \ \ \ | / /
/ / / / / / / / / / / / / — \ \ | / / / /
/ / / / / / / / / / / / — \ | / / / / / /
/ / / / / / / / / / / — | / / / / / / / /
/ / / / / / / / / / | / / / / / / / / / /
/ / / / / / / / | — / / / / / / / / / / /
/ / / / / / | \ — / / / / / / / / / / / /
/ / / / | \ \ — / / / / / / / / / / / / /
/ / | \ \ \ — / / / / / / / / / / / / / /
| \ \ \ \ — / / / / / / / / / / / / / / /
\ \ \ \ — / / / / / / / / / / / / / / / /
\ \ \ — / / / / / / / / / / / / / / / / /
\ \ — / / / / / / / / / / / / / / / / / /
\ — / / / / / / / / / / / / / / / / / / /
— / / / / / / / / / / / / / / / / / / / /
Please separate each point with a space.
f(x, y)
which is passed to our program. \$\endgroup\$