Skip to content Skip to sidebar Skip to footer

How To Use Sin(x) And Cos(x) Functions With Eval

I need a program which can make graphs by matplotlib with functions I write in the console. But it doesn't work with trigonometric functions. The code I already wrote is: from num

Solution 1:

I Don't exactly understand what you want to do but that might help:

from numpy import linspace, sin, cos, tan
import matplotlib.pyplot as plt

a = float(input('Enter x0: '))
b = float(input('Enter x1: '))
x = linspace(a, b, 1001)

for trig_func in [sin, cos]:
    y = trig_func(x)
    plt.title(f'{trig_func.__name__}(x)')
    plt.plot(x, y)
    plt.xlabel('x')
    plt.ylabel('y')
    plt.show()

Please explain how you try to implement eval function..

Solution 2:

i need to make a program wich will describe function i write in console my program already works with for example x**2, or x+2, but it doesnt work with trigonometrical functions. I need my program to can do it both

Post a Comment for "How To Use Sin(x) And Cos(x) Functions With Eval"