GithubHelp home page GithubHelp logo

Comments (5)

bjodah avatar bjodah commented on July 22, 2024 1

I see, one way for lambdify to already raise an exception is to use a printer without allow_unknown_functions set to False. Example:

>>> from sympy.printing.numpy import NumPyPrinter as P
>>> p = P({'inline': True, 'allow_unknown_functions': False})  # 2nd opt defaults to False, but True in lambdify
>>> lambdify(x, parse_expr('nonsense(x)'), printer=p)
PrintMethodNotImplementedError: Unsupported by <class 'sympy.printing.numpy.NumPyPrinter'>: nonsense
Set the printer option 'strict' to False in order to generate partially printed code.

Exactly how to inject this into the sympy.plotting machinery is unfortunately not something I'm familiar with.

from sympy.

bjodah avatar bjodah commented on July 22, 2024

It's a bit hard to give advice here. If there is an underlying issue with sympy at play here, this is the right place to ask, but I don't think you've given us all the relevant code? (from the traceback I see lambdify being used, but I see no call to lambdify in your provided code).

If your question is about how to structure your code (what to put in try/except blocks, in your case perhaps both the parsing of the string, as well as the call doing the numerical evaluation is what you want), then the "Discussions" tab or one of stackexchange's sites is a better place to discuss design of 3rd party libraries/applications?

from sympy.

Napain avatar Napain commented on July 22, 2024

It's a bit hard to give advice here. If there is an underlying issue with sympy at play here, this is the right place to ask, but I don't think you've given us all the relevant code? (from the traceback I see lambdify being used, but I see no call to lambdify in your provided code).

Here are my import. I don't use the lambdify function in any of my code.

from sympy.plotting import plot 
from sympy import * 

I y try with a condition like this one (Code below for the method "plot_any") It is also import to note that I name my class "check_methods" This is a rookie mistake by me, it should be name "CheckMethods" so we undertand is a class.

class Plot(check_methods):

    def __init__(self):
        pass

    def plot_any (self):
        checking = CheckMethods('Input your equation : ')
        equation = checking.check_sympy_equation()
        function = str(equation)
        if equation != False:
             print( ":---------------------",equation, ":---------------------")
             x_min, x_max = self.linspace()
             x = symbols('x') 
             plot(equation,(x,x_min,x_max), line_color = 'red')

Anyway, this condition allow me to check if the input is passing the Check on the try/except blocks. Again If a pass an input like "2?0~" The try/except block actually return the False and the code works as I intended.

I figured this transformation comes from a "valid" input in the try block like "sinus(x)" (instead of sin(x)).
the input "sinus(x)" is a valid input, but the plot method doesn't recognize the "sinus(x)" and throws an error.

I was thinking of doing another method that checks if the plot is possible. I just want to know what simpify allows input that are not "plotable"

from sympy.

sylee957 avatar sylee957 commented on July 22, 2024

What is the code for self.linspace?
I think that you are hiding some details about the class, however, please show the details about the class because we cannot investigate the problem further.

however, the error is likely from giving wrong type for x_min, x_max
x_min, x_max should always be Python numbers, or SymPy numbers, and you may likely have some symbolic expressions that has variables like x, which does not have concrete numeric values, and which is invalid for plotting.

from sympy.

Napain avatar Napain commented on July 22, 2024

What is the code for self.linspace? I think that you are hiding some details about the class, however, please show the details about the class because we cannot investigate the problem further.

however, the error is likely from giving wrong type for x_min, x_max x_min, x_max should always be Python numbers, or SymPy numbers, and you may likely have some symbolic expressions that has variables like x, which does not have concrete numeric values, and which is invalid for plotting.

self.linspace is a method from the class Plot.
and here is the code for the method.

class Plot(CheckMethods): #Need to check the plot any with plot errors

    def __init__(self):
        pass

    def linspace(self):
        first_x = CheckMethods("Please choose the min value of x: ")
        x_min = first_x.check_float()
        second_x = CheckMethods("Please choose the max value of x: ")
        x_max = second_x.check_float()
        return x_min, x_max

Of course, since there also the usage of checking if the inputs are numbers. I also added a method for the CheckMethods class here below

class CheckMethods:

    def __init__(self, the_string):

        self.number = input(the_string)

    def check_float(self):

        while True:
            try:
                self.number = float(self.number)
                return(self.number)
            except ValueError:
                self.number = input('Please input a number')

I don't share the full project because, first is a project for Uni and I want it to keep it private until I summit it. Second It's long and I thought the necessary code was provide. I apologize for taking so long to answer and not providing enough code.

Don't hesitate to ask for more code. Once I finish it I will gladly share the integrity of my project!

from sympy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.