All Samples(2949) | Call(2655) | Derive(0) | Import(294)
sin(x[, out])
Trigonometric sine, element-wise.
Parameters
----------
x : array_like
Angle, in radians (:math:`2 \pi` rad equals 360 degrees).
Returns
-------
y : array_like
The sine of each element of x.
See Also
--------
arcsin, sinh, cos
Notes
-----
The sine is one of the fundamental functions of trigonometry
(the mathematical study of triangles). Consider a circle of radius
1 centered on the origin. A ray comes in from the :math:`+x` axis,
makes an angle at the origin (measured counter-clockwise from that
axis), and departs from the origin. The :math:`y` coordinate of
the outgoing ray's intersection with the unit circle is the sine
of that angle. It ranges from -1 for :math:`x=3\pi / 2` to
+1 for :math:`\pi / 2.` The function has zeroes where the angle is
a multiple of :math:`\pi`. Sines of angles between :math:`\pi` and
:math:`2\pi` are negative. The numerous properties of the sine and
related functions are included in any standard trigonometry text.
Examples
--------
Print sine of one angle:
>>> np.sin(np.pi/2.)
1.0
Print sines of an array of angles given in degrees:
>>> np.sin(np.array((0., 30., 45., 60., 90.)) * np.pi / 180. )
array([ 0. , 0.5 , 0.70710678, 0.8660254 , 1. ])
Plot the sine function:
>>> import matplotlib.pylab as plt
>>> x = np.linspace(-np.pi, np.pi, 201)
>>> plt.plot(x, np.sin(x))
>>> plt.xlabel('Angle [rad]')
>>> plt.ylabel('sin(x)')
>>> plt.axis('tight')
>>> plt.show()src/m/a/matplotlib-HEAD/py4science/examples/numpytemps.py matplotlib(Download)
import nose
# convenience global names
from numpy import (pi, sin, cos, add, subtract, multiply, power)
def test1():
"""Verify an expression using temporaries.
# 4.5*cos(3*x**2): 4
# The final temporaries for each term are added and the result stored as y,
# which is also created. So we have 1 array for the result and 7 temps.
y = sin(x) + sin(2*x) - 4.5*cos(3*x**2)
# Now we do it again, but here, we control the temporary creation
# ourselves. We use the output argument of all numpy functional forms of
# store the output back into the temporary or we accumulate it in z.
# sin(x)
sin(x,z)
# + sin(2*x)
add(z,sin(multiply(2,x,tmp),tmp),z)
def test2():
"""Compute the same expression, using in-place operations
"""
x = np.linspace(0,2*pi,100)
y = sin(x) + sin(2*x) - 4.5*cos(3*x**2)
# This version of the code uses more in-place operators, which make it a
# bit more readable and still avoid temporaries
tmp = np.empty_like(x)
# sin(x)
z = sin(x)
z = sin(x)
# + sin(2*x)
z += sin(multiply(2,x,tmp),tmp)
# - 4.5*cos(3*x**2)
power(x,2,tmp)
src/o/p/openrave-HEAD/trunk/python/examples/hanoi.py openrave(Download)
from openravepy import Environment, IkParameterization, planning_error, raveLogInfo, raveLogWarn, OpenRAVEGlobalArguments, RaveDestroy from openravepy.interfaces import BaseManipulation, TaskManipulation from openravepy.databases import inversekinematics from numpy import array, arange, linalg, pi, dot, vstack, cos, sin, cross, r_, c_ from optparse import OptionParser class HanoiPuzzle:
for ang in arange(-pi,pi,0.3):
# find the dest position
p = Tpeg[0:3,3:4] + height * dest_upvec
R = dot(Tpeg[0:3,0:3], array(((cos(ang),-sin(ang),0),(sin(ang),cos(ang),0),(0,0,1))))
T = dot(r_[c_[R,p], [[0,0,0,1]]], Tdiff)
with self.env:
# check the IK of the destination
def GetGrasp(self, Tdisk, radius, angles):
""" returns the transform of the grasp given its orientation and the location/size of the disk"""
zdir = -dot(Tdisk[0:3,0:3],vstack([cos(angles[0])*cos(angles[1]),-cos(angles[0])*sin(angles[1]),-sin(angles[0])]))
pos = Tdisk[0:3,3:4] + radius*dot(Tdisk[0:3,0:3],vstack([cos(angles[1]),-sin(angles[1]),0]))
xdir = cross(Tdisk[0:3,1:2],zdir,axis=0)
xdir = xdir / linalg.norm(xdir)
ydir = cross(zdir,xdir,axis=0)
src/o/p/openrave-HEAD/python/examples/hanoi.py openrave(Download)
from openravepy import Environment, IkParameterization, planning_error, raveLogInfo, raveLogWarn, OpenRAVEGlobalArguments from openravepy.interfaces import BaseManipulation, TaskManipulation from openravepy.databases import inversekinematics from numpy import array, arange, linalg, pi, dot, vstack, cos, sin, cross, r_, c_ from optparse import OptionParser class HanoiPuzzle:
for ang in arange(-pi,pi,0.3):
# find the dest position
p = Tpeg[0:3,3:4] + height * dest_upvec
R = dot(Tpeg[0:3,0:3], array(((cos(ang),-sin(ang),0),(sin(ang),cos(ang),0),(0,0,1))))
T = dot(r_[c_[R,p], [[0,0,0,1]]], Tdiff)
with self.env:
# check the IK of the destination
def GetGrasp(self, Tdisk, radius, angles):
""" returns the transform of the grasp given its orientation and the location/size of the disk"""
zdir = -dot(Tdisk[0:3,0:3],vstack([cos(angles[0])*cos(angles[1]),-cos(angles[0])*sin(angles[1]),-sin(angles[0])]))
pos = Tdisk[0:3,3:4] + radius*dot(Tdisk[0:3,0:3],vstack([cos(angles[1]),-sin(angles[1]),0]))
xdir = cross(Tdisk[0:3,1:2],zdir,axis=0)
xdir = xdir / linalg.norm(xdir)
ydir = cross(zdir,xdir,axis=0)
src/a/l/algopy-HEAD/documentation/AD_tutorial_TU_Berlin/example7_simple_computation_of_the_hessian.py algopy(Download)
at x = (3,7)
"""
import numpy; from numpy import sin,cos, array, zeros
from taylorpoly import UTPS
def f_fcn(x):
return sin(x[0] + cos(x[1])*x[0])
def H_fcn(x):
H11 = -(1+cos(x[1]))**2*sin(x[0]+cos(x[1])*x[0])
H21 = -sin(x[1]) * cos(x[0] + cos(x[1])*x[0]) \
+sin(x[1]) *x[0]*(1+ cos(x[1]))*sin(x[0]+cos(x[1])*x[0])
H22 = -cos(x[1])*x[0]*cos(x[0]+cos(x[1])*x[0])\
-(sin(x[1])*x[0])**2*sin(x[0]+cos(x[1])*x[0])
return array([[H11, H21],[H21,H22]])
src/m/a/matplotlib-HEAD/matplotlib/examples/pylab_examples/vline_demo.py matplotlib(Download)
#!/usr/bin/env python
from matplotlib.pyplot import *
from numpy import sin, exp, absolute, pi, arange
from numpy.random import normal
def f(t):
s1 = sin(2*pi*t)
src/m/a/matplotlib-HEAD/matplotlib/examples/pylab_examples/color_by_yvalue.py matplotlib(Download)
# use masked arrays to plot a line with different colors by y-value from numpy import logical_or, arange, sin, pi from numpy import ma from matplotlib.pyplot import plot, show t = arange(0.0, 2.0, 0.01) s = sin(2*pi*t)
src/m/a/matplotlib-HEAD/examples/pylab_examples/vline_demo.py matplotlib(Download)
#!/usr/bin/env python
from matplotlib.pyplot import *
from numpy import sin, exp, absolute, pi, arange
from numpy.random import normal
def f(t):
s1 = sin(2*pi*t)
src/m/a/matplotlib-HEAD/matplotlib/examples/pylab_examples/errorbar_limits.py matplotlib(Download)
''' Illustration of upper and lower limit symbols on errorbars ''' from math import pi from numpy import array, arange, sin import pylab as P fig = P.figure() x = arange(10.0) y = sin(arange(10.0)/20.0*pi)
P.errorbar(x,y,yerr=0.1,capsize=3) y = sin(arange(10.0)/20.0*pi) + 1 P.errorbar(x,y,yerr=0.1, uplims=True) y = sin(arange(10.0)/20.0*pi) + 2
src/m/a/matplotlib-HEAD/examples/pylab_examples/color_by_yvalue.py matplotlib(Download)
# use masked arrays to plot a line with different colors by y-value from numpy import logical_or, arange, sin, pi from numpy import ma from matplotlib.pyplot import plot, show t = arange(0.0, 2.0, 0.01) s = sin(2*pi*t)
src/p/y/pyfusion-HEAD/examples/test_savez.py pyfusion(Download)
# debug_save_compress=False;
global verbose
from numpy import savez, array, arange, remainder, mod, sin, pi, min, max, \
size, diff, random, mean, unique, sort, sqrt, float32
from time import time
from pylab import plot, show
# First put in the range 0,2^n-1 bits=14 t=arange(2000)*1e-6 rdata=2000*sin(5e3*2*pi*t) plot(t[0:maxp],rdata[0:maxp],'c',hold=0) plot(t[0:maxp],rdata[0:maxp],'.b',hold=1,markersize=1.5) show()
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Next