##Create a function that will perform the following calculation on a given input value: ?=5sin(?−6?12) . (The input value here is ? , and ?=3.14159... is a constant.)
import math
from sympy.abc import x
def sin_f(x):
y = 5 * math.sin((x-6*math.pi)/12)
return y
print(sin_f(math.radians(95)))
##Complete the loop below to create a list named "x_list" that contains values ranging from 0 to 100, incremented by 0.25 (i.e.; 0, 0.25, 0.5, ... 99.5, 99.75, 100). Print out the list after creating it.
x_list = []
maxCount = 100
count = 0
while(count < maxCount):
x_list.append(count)
count = count + 0.25
print(x_list)
##Now create "y_list", which contains the value ? as defined in your function, given the ? values from "x_list". Then, print the first value of "y_list".
y_list = []
i = 0
for i in range(len(x_list)):
y = 5 * math.sin((x-6*math.pi)/12)
y_list.append(y)
i = i + 1
print(y_list[1])
##Run the cell below to plot "x_list" against "y_list". Don't worry about understanding what that code is doing just yet. We will get to plotting later.
%pylab inline
import matplotlib.pyplot as pl
pl.plot(x_list,y_list)
pl.xlabel('x')
pl.ylabel('y')
pl.show()
##Create a new function called "y_from_list" that takes in an entire list of ? values as input, and then calculates all of the corresponding ? values and returns a list of those ? values.
def y_from_list(input_list):
output_list = []
for j in range(len(input_list)):
output_list.append(y_from_list)
return output_list
##If the function you just wrote is working properly, it should run the following cell:
y_list2 = y_from_list(x_list)
pl.plot(x_list,y_list,ls=':',linewidth=3,label='y_list')
pl.plot(x_list,y_list2,linewidth=1,label='y_list2')
pl.xlabel('x')
pl.ylabel('y')
pl.legend()
pl.show()
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}