python三角函数图像 python求解三角函数方程

简单python语言编程:采用自顶向下设计方法编写程序:在屏幕上打印三角函数y = sin(x)的图像 。I just wrote an simple one for one other guy.
You may check it here and see if it's useful for you.
Python中计算三角函数之cos()方法的使用简介这篇文章主要介绍了Python中计算三角函数之cos()方法的使用简介,是Python入门的基础知识,需要的朋友可以参考下
cos()方法返回x弧度的余弦值 。
语法
以下是cos()方法的语法:
cos(x)
注意:此函数是无法直接访问的,所以我们需要导入math模块,然后需要用math的静态对象来调用这个函数 。
参数
x
--
这必须是一个数值
返回值
此方法返回-1

1之间的数值,它表示角度的余弦值
例子
下面的例子展示cos()方法的使用
?
1
2
3
4
5
6
7
8#!/usr/bin/python
import
math
print
"cos(3)
:
",
math.cos(3)
print
"cos(-3)
:
",
math.cos(-3)
print
"cos(0)
:
",
math.cos(0)
print
"cos(math.pi)
:
",
math.cos(math.pi)
print
"cos(2*math.pi)
:
",
math.cos(2*math.pi)
【python三角函数图像 python求解三角函数方程】当我们运行上面的程序,它会产生以下结果:
?
1
2
3
4
5cos(3)
:
-0.9899924966
cos(-3)
:
-0.9899924966
cos(0)
:
1.0
cos(math.pi)
:
-1.0
cos(2*math.pi)
:
1.0
如何用python完成:用自顶向下设计方法编写程序:在屏幕上打印三角函数y = sin(x)的图像 。I wrote this in Tkinter for you, in case you don't know Tkinter, it is a built-in module for most python versions.
If you want a commandline version, you can ask me, but tell you what, since those values are all
float numbers, so it's hard to get a precise graph in commandline window.
Well, in this version, I enlarged each element's position by 40 and then change them to integer, guess this is an endurable loss of precision.
#
from math import radians
from math import sin
from Tkinter import *
pos = []
xPos = 0
centerX = 0
centerY = 0
for deg in range(-360, 361, 10):
pos.append([xPos, int(40*(sin(radians(deg))))]) #1000 too big for my screen
xPos+=1
if deg == 0:
centerX = xPos-1
centerY = pos[-1][1]
root = Tk()
root.title('trianble graph from -180 to 180')
width, height = 550, 450
mHei = height/2
mWid = width/2
canvas = Canvas(root, width=width, height=height)
canvas.create_line(0, mHei, width, mHei)#x axis
canvas.create_line(mWid, 0, mWid, height)#y axis
xStep = (width-150)/len(pos)
yStep = (height-150)/len(pos)
radius = 3
# the middle point (sin(0) is first drawn and used as position reference for all
canvas.create_oval(mWid-radius, mHei-radius, mWid+radius, mHei+radius, fill='green')
print pos
print xStep, yStep, centerX, centerY
#exit(0)
for i in pos:
if i[0] == centerX: #center processed already.
continue
x = mWid + xStep*(i[0]-centerX)
# y is smaller, the bigger the value, so use minus
y = mHei - yStep*(i[1]-centerY)
canvas.create_oval(x-radius, y-radius, x+radius, y+radius, fill='green')
canvas.pack()
root.mainloop()
如何用python表示三角函数在python中,有一个math module , 你可以import math,里面有math.sin(), math.cos(), math.asin()和math.acos()四个函数 。相信你也知道asin和acos的意思,就是arcsin和arccos 。有了这四个函数你就可以求函数值和角度了 。但是要注意括号里面填的数值,要用弧度制 。

推荐阅读