1

I have figured out how to make a equation with SymPy, however, I am not sure how to plot the relationship between two values. I keep getting an TypeError: Cannot convert expression to float whenever I write plt.plot(Rho , T). I have a code like this so far:

import matplotlib as plt
from sympy import init_session

init_session()

rho, X, Y, Z, T_9, T, T_8, m, n, Gamma = symbols('rho X Y Z T_9 T T_8 m n Gamma')

q_pp = (2.4 * 10**(4) * rho * X**2 / T_9**(2/3)) * exp((-3.380/T_9**(1/3)))
q_CNO = (4.4 * 10**(25) * rho * X* Z/ T_9**(2/3)) * exp((-15.228/T_9**(1/3)))

q_min = q_pp + q_CNO
simplify(q_min)

T_9 = T / (10**9)

Rho = (10**3)*(T_9**(1/3) / (24000 * X * exp(15.228/T_9**(1/3)) + (4.4*10**25) * Z * exp(3.38/T_9**(1/3)))) * exp(-18.608/ T_9**(1/3))
simplify(Rho)

plot_implicit(T, Rho)

Updated: I used SymPy plot to get new error, I updated the code to reflect what I currently have, TypeError: object of type 'Mul' has no len()

Casper
  • 27
  • 3
  • 3
    Please provide enough code so others can better understand or reproduce the problem. – Community Oct 29 '22 at 02:46
  • Matplotlib doesn't understand about sympy expressions. You'll need sympy's plot. – JohanC Oct 29 '22 at 12:27
  • Okay, so I tried sympy plot, and I got a new error, this one is `TypeError: object of type 'Mul' has no len()` . So, would I have to use specify a range with `numpy.linspace(, , )` – Casper Oct 29 '22 at 13:53

1 Answers1

0

You need to provide values for the independent variable(s). For example, to plot an expression like y = x**2 - 1, I would do this:

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0, 20)  # Provide the range of the independent variable.
y = x**2 - 1          # Compute the dependent variable.

plt.plot(x, y)

In your case, you'll need to provide values for T I suppose, and it looks like there are several other unknowns too. Take a look at this question, answers to which show a SymPy plotting example.

Matt Hall
  • 7,614
  • 1
  • 23
  • 36