Skip to content

Factor sinp and cosp into library.sage #684

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 3 additions & 19 deletions source/calculus/exercises/outcomes/TI/TI3/generator.sage
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@
#Functions to display powers of trig functions
def print_cosp(self,*args): return f"\\cos ^{{{args[1]}}}({latex(args[0])})"
def deriv_cosp(self,*args,**kwds):
if args[1]==1:
return -1*sinp(args[0],1)*args[0].derivative(args[kwds['diff_param']])
else:
return args[1]*-1*cosp(args[0],args[1]-1)*sinp(args[0],1)*args[0].derivative(args[kwds['diff_param']])

cosp = function("cosp",nargs=2,print_latex_func=print_cosp,derivative_func=deriv_cosp)
def print_sinp(self,*args): return f"\\sin ^{{{args[1]}}}({latex(args[0])})"
def deriv_sinp(self,*args,**kwds):
if args[1]==1:
return cosp(args[0],1)*args[0].derivative(args[kwds['diff_param']])
else:
return args[1]*sinp(args[0],args[1]-1)*cosp(args[0],1)*args[0].derivative(args[kwds['diff_param']])

sinp = function("sinp",nargs=2,print_latex_func=print_sinp, derivative_func=deriv_sinp)
load("../../../source/common/sagemath/library.sage")

class Generator(BaseGenerator):

Expand All @@ -30,7 +14,7 @@ class Generator(BaseGenerator):
hint=f"(1-z)^{m}={latex(sum(binomial(m,k)*(-z)^k,k,0,m))}"


trigs=[sinp, cosp]
trigs=[TBIL.sinp, TBIL.cosp]
shuffle(trigs)

a = randint(1,6)
Expand All @@ -44,7 +28,7 @@ class Generator(BaseGenerator):
m = randrange(2,5)
n = randrange(2,5)
k = 2^randrange(2,5)
g = k*cosp(a*x,2*m)*sinp(a*x,2*n)
g = k*TBIL.cosp(a*x,2*m)*TBIL.sinp(a*x,2*n)
also_g = k/2^(m+n)*(1+cos(2*a*x))^m*(1-cos(2*a*x))^n


Expand Down
21 changes: 21 additions & 0 deletions source/common/sagemath/library.sage
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,27 @@ class TBIL:
'''Returns the equation of a line from a point and slope'''
return y==slope*x+point[1]-slope*point[0]

#Functions to display powers of trig functions
def print_cosp(self,*args): return f"\\cos ^{{{args[1]}}}({latex(args[0])})"

def deriv_cosp(self,*args,**kwds):
if args[1]==1:
return -1*TBIL.sinp(args[0],1)*args[0].derivative(args[kwds['diff_param']])
else:
return args[1]*-1*TBIL.cosp(args[0],args[1]-1)*TBIL.sinp(args[0],1)*args[0].derivative(args[kwds['diff_param']])

cosp = function("cosp",nargs=2,print_latex_func=print_cosp,derivative_func=deriv_cosp)

def print_sinp(self,*args): return f"\\sin ^{{{args[1]}}}({latex(args[0])})"

def deriv_sinp(self,*args,**kwds):
if args[1]==1:
return TBIL.cosp(args[0],1)*args[0].derivative(args[kwds['diff_param']])
else:
return args[1]*TBIL.sinp(args[0],args[1]-1)*TBIL.cosp(args[0],1)*args[0].derivative(args[kwds['diff_param']])

sinp = function("sinp",nargs=2,print_latex_func=print_sinp, derivative_func=deriv_sinp)

# Linear Algebra

@staticmethod
Expand Down