Comments (5)
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.
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.
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.
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.
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 likex
, 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)
- Feature Request: Add Import/Export Functions for Boolean Expressions in Z3 and BDD Formats HOT 15
- Wrong translation of lerchphi into Mathematica HOT 3
- Add a factors function to get factors without multiplicity HOT 7
- collected_expr.coeff() always return 0 if some symbol was used as a Divisor? HOT 2
- Solution from dsolve_system violates all equations HOT 2
- Sympify broken for latest numpy numbers HOT 4
- Control test fails with numpy 2.0 HOT 15
- Investigation about the forward_jacobian Function HOT 27
- Pretty printer occasionally raises TypeError when displaying vectors from the mechanics module on Jupyter Notebook HOT 7
- ufuncify fails with NumPy 2.0 for specific symbol names HOT 1
- Add a function to convert algebraic numbers to RootOf HOT 1
- Sparse Matrix Multiplication Performance HOT 4
- function_range is not robust with trigonometric functions HOT 3
- Automatic simplification of expressions involving `AlgebraicNumber` HOT 2
- Incorrect result for definite integral related to gaussian integral HOT 1
- SymPy pauli algebra should simplify terms if labels are in a different order?
- Missing Pre-release Tags for 1.13.0rc3 etc HOT 4
- Printing Parsed Mathematica Code exception HOT 1
- npartitions incorrect for n=11160 HOT 2
- Not all time derivatives are replaced when forming Kane's equations HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sympy.