Ask Your Question

Revision history [back]

ValueError: free variable x |--> x when ploting the function x

Hi all.

I got the following problem:

sage: plot(symbolic_expression(x).function(x))

this raises

ValueError: free variable: x |--> x

If I replace x by anything else (but 1*x) it works fine.

How can I do ?

My rationale behind my question is that I have a class which takes a function as argument and can perform many thinks on it, among other the plot. I made the following :

class MyFuncion(object):
    def __init__(self,f):
        self.f=symbolic_expression(f).function(x)
    def plot(self):
        return plot(self.f)

My point in doing so is that I have to accept, as input f expressions like x**2, 2, g.diff(x) (where g is an other function) and so on. In these cases, it turns out that I need to use the symbolic_expression trick in order to be sure that what I have is a function (need for numerical integration for example)

My questions :

  1. Can I do otherwise in __init__ in order to be sure to be able to use numerical integration, derivative, ... on self.f ?

  2. If not, how can I plot when the input is simply "x" ?

click to hide/show revision 2
No.2 Revision

ValueError: free variable x |--> x when ploting plotting the function x

Hi all.

I got the following problem:

sage: plot(symbolic_expression(x).function(x))

this raises

ValueError: free variable: x |--> x

If I replace x by anything else (but 1*x) it works fine.

How can I do ?

My rationale behind my question is that I have a class which takes a function as argument and can perform many thinks on it, among other the plot. I made the following :

class MyFuncion(object):
MyFunction(object):
    def __init__(self,f):
        self.f=symbolic_expression(f).function(x)
    def plot(self):
        return plot(self.f)

My point in doing so is that I have to accept, as input f expressions like x**2, 2, g.diff(x) (where g is an other function) and so on. In these cases, it turns out that I need to use the symbolic_expression trick in order to be sure that what I have is a function (need for numerical integration for example)

My questions :

  1. Can I do otherwise in __init__ in order to be sure to be able to use numerical integration, derivative, ... on self.f ?

  2. If not, how can I plot when the input is simply "x" ?

click to hide/show revision 3
retagged

ValueError: free variable x |--> x when plotting the function x

Hi all.

I got the following problem:

sage: plot(symbolic_expression(x).function(x))

this raises

ValueError: free variable: x |--> x

If I replace x by anything else (but 1*x) it works fine.

How can I do ?

My rationale behind my question is that I have a class which takes a function as argument and can perform many thinks on it, among other the plot. I made the following :

class MyFunction(object):
    def __init__(self,f):
        self.f=symbolic_expression(f).function(x)
    def plot(self):
        return plot(self.f)

My point in doing so is that I have to accept, as input f expressions like x**2, 2, g.diff(x) (where g is an other function) and so on. In these cases, it turns out that I need to use the symbolic_expression trick in order to be sure that what I have is a function (need for numerical integration for example)

My questions :

  1. Can I do otherwise in __init__ in order to be sure to be able to use numerical integration, derivative, ... on self.f ?

  2. If not, how can I plot when the input is simply "x" ?