From 50949a7c1d01430f207065ddad5e51c8e38fc665 Mon Sep 17 00:00:00 2001 From: Drew Lewis Date: Wed, 18 Dec 2024 09:18:51 -0800 Subject: [PATCH 1/2] TI3 task 2 --- source/calculus/exercises/outcomes/TI/TI3/generator.sage | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/source/calculus/exercises/outcomes/TI/TI3/generator.sage b/source/calculus/exercises/outcomes/TI/TI3/generator.sage index 0c92a0cd8..e6eb90c00 100644 --- a/source/calculus/exercises/outcomes/TI/TI3/generator.sage +++ b/source/calculus/exercises/outcomes/TI/TI3/generator.sage @@ -1,4 +1,11 @@ +#Functions to display powers of trig functions +def print_cosp(self,*args): return f"\\cos ^{args[1]}({latex(args[0])})" +cosp = function("cosp",nargs=2,print_latex_func=print_cosp) +def print_sinp(self,*args): return f"\\sin ^{args[1]}({latex(args[0])})" +sinp = function("sinp",nargs=2,print_latex_func=print_sinp) + class Generator(BaseGenerator): + def data(self): # integral with odd power x=var("x") @@ -26,7 +33,7 @@ class Generator(BaseGenerator): m = randrange(2,5) n = randrange(2,5) k = 2^randrange(2,5) - g = k*cos(a*x)^(2*m)*sin(a*x)^(2*n) + g = k*cosp(a*x,2*m)*sinp(a*x,2*n) also_g = k/2^(m+n)*(1+cos(2*a*x))^m*(1-cos(2*a*x))^n From fe59d3db18f940a6ec7a5d75acc2a82d4b0cb283 Mon Sep 17 00:00:00 2001 From: Drew Lewis Date: Wed, 18 Dec 2024 10:17:39 -0800 Subject: [PATCH 2/2] Refactor task 1 --- .../exercises/outcomes/TI/TI3/generator.sage | 49 ++++++++++++------- .../exercises/outcomes/TI/TI3/template.xml | 10 +--- 2 files changed, 32 insertions(+), 27 deletions(-) diff --git a/source/calculus/exercises/outcomes/TI/TI3/generator.sage b/source/calculus/exercises/outcomes/TI/TI3/generator.sage index e6eb90c00..e2afa39d5 100644 --- a/source/calculus/exercises/outcomes/TI/TI3/generator.sage +++ b/source/calculus/exercises/outcomes/TI/TI3/generator.sage @@ -1,33 +1,44 @@ #Functions to display powers of trig functions -def print_cosp(self,*args): return f"\\cos ^{args[1]}({latex(args[0])})" -cosp = function("cosp",nargs=2,print_latex_func=print_cosp) -def print_sinp(self,*args): return f"\\sin ^{args[1]}({latex(args[0])})" -sinp = function("sinp",nargs=2,print_latex_func=print_sinp) +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) class Generator(BaseGenerator): def data(self): - # integral with odd power + # Task 1, integral with odd power x=var("x") - even=2*randint(1,6) - - odd=choice([5,7]) + n=randint(1,6) + m=randint(2,3) - z = var("z") - if odd==5: - hint = "hint_2" - else: - hint = "hint_3" + k=var('k') + z=var('z') + hint=f"(1-z)^{m}={latex(sum(binomial(m,k)*(-z)^k,k,0,m))}" - trigs=[sin, cos] - shuffle(trigs) - f=randint(1,5)*(trigs[0](x))^even*(trigs[1](x))^odd + trigs=[sinp, cosp] + shuffle(trigs) - F=f.integral(x) + a = randint(1,6) + f = a*trigs[0](x,2*n)*trigs[1](x,2*m+1) + F = sum(a*binomial(m,k)*(-1)^k*1/(2*n+2*k+1)*trigs[0](x,2*n+2*k+1)*trigs[0](x,1).derivative(x)/trigs[1](x,1),k,0,m) + - # integral with even powers + # Task 2, integral with even powers a = randrange(2,6) m = randrange(2,5) @@ -42,5 +53,5 @@ class Generator(BaseGenerator): "F": F, "g": g, "also_g": also_g, - hint: True, + "hint": hint, } diff --git a/source/calculus/exercises/outcomes/TI/TI3/template.xml b/source/calculus/exercises/outcomes/TI/TI3/template.xml index 0377ef9f6..6239538d2 100644 --- a/source/calculus/exercises/outcomes/TI/TI3/template.xml +++ b/source/calculus/exercises/outcomes/TI/TI3/template.xml @@ -3,14 +3,8 @@

-Use trigonometric identities and -{{#hint_2}} -(1-z)^2=1-2z+z^2 -{{/hint_2}} -{{#hint_3}} -(1-z)^3=1-3z+3z^2-z^3 -{{/hint_3}} -to explain and demonstrate how to find +Using trigonometric identities and the fact that {{hint}}, +explain and demonstrate how to find \displaystyle \int {{f}} dx.