Connect symbols to numbersLesson 44 of 48 · 8 min
Evaluate a curve on an array
Use a NumPy-backed symbolic function to plot a domain-labelled curve.
Maths refresher: A graph samples a function
A graph places input on one axis and output on the other. A numerical grid evaluates only its selected inputs.
Sampling between 0 and 4 shows part of the decay. It does not display every nonnegative input or prove a long-time limit.
A NumPy-backed lambdified function can evaluate many inputs in one call. This connects a symbolic derivation with numerical arrays and plots. Preserve the domain and units when selecting the input grid.
The example plots a known response for nonnegative x. The symbolic expression remains available for exact values, while the plotted samples are floating-point evaluations. A grid is a set of sampled locations, not the whole continuous function.
Plots are useful for interpretation and catching surprising behaviour, but a smooth-looking curve is not a proof of continuity, an identity or exhaustive root coverage. Check exact boundaries and singularities from the symbolic model rather than relying on a finite grid to reveal them.
Does a plot on 200 points examine every input between the endpoints?
Write a prediction (optional)
Symbolic curve and sampled numerical values
Select Run Python with the code unchanged.
Your saved draft is open. To use the published code, select Restore example in Tools. Use Recover draft to bring back your code.
Tools
About Python
Python and the course packages can load while you read. Each run starts with fresh user variables; imported modules stay loaded. Stop replaces the worker. Runtime details ↗
Ctrl+Enter or ⌘+Enter runs Python.
Execution error
Technical error details
Your result
Python text output
Compare with the worked example
Executed from the published Python during the site build. Your own run appears above. Build environment ↗
Worked text output
Symbolic curve: exp(-x) Exact starting value: 1 Sampled endpoint: 0.01831563888873418 Grid points: 200
Read the starter result
The plot comes from the current numerical samples. Exact starting value comes from symbolic substitution. Sampled endpoint comes from the last point in the floating-point grid.
Edit and compare
Replace expression = sp.exp(-x) with expression = sp.sin(x) and end = 4 with end = 2*sp.pi. Change the x-axis label string to "x (radians)". Select Run Python. Then change points = 200 to points = 25 and select Run Python again. Compare the plots, Grid points and Sampled endpoint.
Scope. Finite plotting grids can conceal singularities and narrow features; this smooth bounded example deliberately avoids those difficulties.
Try a fresh case
A plotted curve seems to cross zero once. What further work supports a claim about all roots?
Need a hint?
Hint 1
Think about what lies between grid points.
Hint 2
Use the formula and domain, not just the drawing.