Sympy – integrate then plot an expression

By cqcn1991

enter image description here

Here is the equation that I want to integrate, I want to integrate the theta, it will be a function of y = f(V), then plot the y - V. All other parameters are known.

How can I do it?

Here is what I’ve done:

# Part 1: Create integ_expr y=f(V)
from sympy import *
from __future__ import division
import numpy as np
import matplotlib.pyplot as plt
V, theta = symbols('v theta')
# U, phi, sigu, sigv = symbols('U phi sigu sigv')
u,v = -2.63582726849, 0.562272364634
sigu, sigv = 7.9369982103, 6.56056711043
U = (u)**2 + (v)**2
phi = atan(u/v)
expr = exp(((V*cos(theta)-U*cos(phi))**2/sigu**2+(V*sin(theta)-U*sin(phi))**2/sigv**2)*-1/2)
integ_expr = integrate(expr, (theta, 0, 2*np.pi)) # this can return a result
# Part 2: plot `y-V`
lf = lambdify(V, integ_expr)
fig = plt.figure()
x_vals = np.linspace(-20.,20.)
y_vals = lf(x_vals) # reports TypeError: can't convert expression to float
axes.plot(x_vals, y_vals);

I can get the integ_expr, but y_vals = lf(x_vals) gives me TypeError: can't convert expression to float.

I think it’s maybe the integ_expr is still an expression not a function that can directly return a result?

I just get started with Sympy, the above code may feel childish to most of you, so I’m wondering if there is a right way to plot expressions?

Source: Stack Overflow


Share it with your friends!

    Fatal error: Uncaught Exception: 12: REST API is deprecated for versions v2.1 and higher (12) thrown in /home/content/19/9652219/html/wp-content/plugins/seo-facebook-comments/facebook/base_facebook.php on line 1273