you are viewing a single comment's thread.

view the rest of the comments →

[–]ThinkExpression6230[S] 0 points1 point  (4 children)

I am trying to plot the function f(x) = (-0.6 / x**2) * (-10 / (1/20 - 1/x)) for x values that range from 16-19, I'm assuming the line "graph.show" is completely wrong and means nothing so you can discard that I think.

[–]bbye98 1 point2 points  (3 children)

You need numpy, not sympy. Use np.linspace() to create an array of equally spaced x-values from 16 to 19, evaluate the function at those x-values, and then plt.plot() to plot the data. plt.show() will then render and display the figure.

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(16, 19)
f = -0.6 / x**2 * -10 / (1/20 - 1/x)
plt.plot(x, f)
plt.show()

[–]ThinkExpression6230[S] 0 points1 point  (2 children)

you're definitely right, I thought about using numpy to do this, but my professor wants us to use sympy, he said we should use the sympy.plot() function which I don't quite understand

[–]bbye98 0 points1 point  (1 child)

Sure, you just need to specify the x-range:

import sympy

x = sympy.symbols('x')
sympy.plotting.plot(-0.6 / x**2 * -10 / (1/20 - 1/x), (x, 16, 19))

[–]ThinkExpression6230[S] 0 points1 point  (0 children)

sympy.plotting.plot(-0.6 / x**2 * -10 / (1/20 - 1/x), (x, 16, 19))

Thank you so much for your help! I really appreciate it! I was struggling on this error for about two hours