如何在eval中使用sin(x)和cos(x)函数 [英] How to use sin(x) and cos(x) functions with eval

查看:491
本文介绍了如何在eval中使用sin(x)和cos(x)函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个程序,该程序可以使用我在控制台中编写的功能通过matplotlib制作图形. 但这不适用于三角函数. 我已经编写的代码是:

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 numpy import linspace
import matplotlib.pyplot as plt
from math import sin, cos, tan

print("input a:")
a = float(input())
print("input b:")
b = float(input())
x = linspace(a, b, 1001)
y = eval(input())

plt.plot(x, y)
plt.xlabel('x')
plt.ylabel('y')
plt.show()

推荐答案

我需要编写一个程序来描述我在控制台中编写的功能 我的程序已经可以使用例如x ** 2或x + 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

这篇关于如何在eval中使用sin(x)和cos(x)函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆