Skip to content

Plotting lambda functions #4677

@kcrisman

Description

@kcrisman

This works:

sage: f=x^2
sage: plot(lambda x:f(x),(x,-1,1))

But this doesn't:

sage: f=x^2
sage: plot(lambda x:f,(x,-1,1))
verbose 0 (3633: plot.py, _plot) WARNING: When plotting, failed to evaluate function at 400 points.
verbose 0 (3633: plot.py, _plot) Last error message: 'float() argument must be a string or a number'

The behavior is the same for f(x)=x^2.

This is because in the second example "evaluating" the lambda function yields a SymbolicCallableExpression, which needs to be called again to actually yield a numerical value.

Component: graphics

Issue created by migration from https://trac.sagemath.org/ticket/4677

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions