Davide-sd / sympy-plot-backends

An improved plotting module for SymPy
BSD 3-Clause "New" or "Revised" License
42 stars 9 forks source link

Missing sympy.integrals.laplace module #31

Closed bawolk closed 9 months ago

bawolk commented 9 months ago
from spb import *
plot_contour(sol_u_approx, (x, 0, 10), (t, 0, 8))

This produces the following error: ModuleNotFoundError Traceback (most recent call last) Cell In[33], line 2 1 # Now we can plot the solution with the sympy plotting backends spb: ----> 2 from spb import * 3 plot_contour(sol_u_approx, (x, 0, 10), (t, 0, 8))

File ~/anaconda3/lib/python3.9/site-packages/spb/init.py:25 20 from spb.vectors import plot_vector 21 from spb.ccomplex.complex import ( 22 plot_complex, plot_complex_list, 23 plot_real_imag, plot_complex_vector, plot_riemann_sphere 24 ) ---> 25 from spb.control import ( 26 plot_pole_zero, plot_step_response, plot_impulse_response, 27 plot_ramp_response, plot_bode_magnitude, plot_bode_phase, plot_bode, 28 plot_nyquist, plot_nichols 29 ) 30 from spb.utils import prange 32 from spb.plotgrid import plotgrid, PlotGrid

File ~/anaconda3/lib/python3.9/site-packages/spb/control.py:14 9 import numpy as np 10 from sympy import (roots, exp, Poly, degree, re, im, latex, apart, Dummy, 11 I, log, Abs, arg, sympify, S, Min, Max, Piecewise, sqrt, 12 floor, ceiling, frac, pi 13 ) ---> 14 from sympy.integrals.laplace import _fast_inverse_laplace 15 from sympy.physics.control.lti import SISOLinearTimeInvariant 16 from mergedeep import merge

ModuleNotFoundError: No module named 'sympy.integrals.laplace'

Davide-sd commented 9 months ago

Hello, thanks for the report. Please, can you provide enough code so that I can reproduce it? Right now, I don't know what sol_u_approx is.

Davide-sd commented 9 months ago

Also, what version of sympy are you using?

import sympy as sp
print(sp.__version__)
bawolk commented 9 months ago

Sorry I gave you so little info. It's a solution to the heat equation taken from this: https://medium.com/@mathcube7/the-diffusion-equation-solved-analytically-with-python-6b59dcae0317 You can see the contour plot at the end of the article.

The version of sympy is 1.11.1 I use conda to install things

Davide-sd commented 9 months ago

Eheh I can't read that, it requires registration.

Please do this on your code:

# here is the code you implemented

from sympy import print_python
print_python(sol_u_approx)

And copy the output on your next reply. This will give me the exact expression so that I can work on that. Thank you for your patience :)

bawolk commented 9 months ago

Thank you for trying to help me. I wasn't aware of the print_python function. Here is the output:

n = Symbol('n') t = Symbol('t') x = Symbol('x') e = Sum(200*(1 - (-1)n)*exp(-pi*2n2t/100)sin(pinx/10)/(pi*n), (n, 1, 30))

bawolk commented 9 months ago

For some reason it dropped a bunch of asterisks. I should have treated it as code:

e = Sum(200*(1 - (-1)**n)*exp(-pi**2*n**2*t/100)*sin(pi*n*x/10)/(pi*n), (n, 1, 30))

Davide-sd commented 9 months ago

Ok, just confirmed the bad import on sympy 1.11.1. For the moment, you can try to update to sympy 1.12. I'll probably release a fix tomorrow or the day after.

n = Symbol('n')
t = Symbol('t')
x = Symbol('x')
e = Sum(200*(1 - (-1)**n)*exp(-pi**2*n**2*t/100)*sin(pi*n*x/10)/(pi*n), (n, 1, 30))
plot_contour(e, (x, 0, 10), (t, 0, 8), {"levels": 20}, grid=False)

image

Davide-sd commented 9 months ago

I just released a new version that should solve this. I believe conda installer will be ready in a few hours, or tomorrow at the most. In the meantime I'm going to close this issue. If you have any problems after the update, feel free to open a new issue :)