Hidden WordScanner
Private scans · No account required

DuckieDai Cos and Sec Graphs

Graph y = A*cos(Bx - C) + D or y = A*sec(Bx - C) + D: the amplitude, period, phase shift, midline, key points, and asymptotes, with the parent graph to compare and a drawing on the calculator.

trigonometry · MIT License

Overview

Graph y = A*cos(Bx - C) + D or y = A*sec(Bx - C) + D: the amplitude, period, phase shift, midline, key points, and asymptotes, with the parent graph to compare and a drawing on the calculator.

  • Owner-tested on a TI calculator
  • Version 1.0.0
  • 2876 bytes
  • Uses math, ti_plotlib

Before you run it

  • TI-84 Plus CE Python · No calculator OS or Python App version has been verified.
  • TI Connect CE .py transfer to the Python App; the owner's transfer details were not recorded
  • The function is y = A*cos(Bx - C) + D or y = A*sec(Bx - C) + D, with B not 0.
  • A, B, C, and D may be decimals, fractions such as 1/2, or multiples of pi such as pi/3 or -2pi.
  • Values are limited to -1,000,000 to 1,000,000; inf and nan are asked for again.

Try the DuckieDai calculator screen

Follow the program's prompts and result flow before downloading.

JavaScript is required for the optional browser simulation. Source viewing and downloading remain available without it.

Simulation boundary: This preview uses a reviewed browser adapter. It does not execute the downloaded Python and does not prove TI-Python or calculator compatibility.

Learn the math

How to graph cosine and secant with transformations

The idea

Cosine waves up and down between a highest and lowest value, so it has an amplitude: half the distance from the top to the bottom. Secant is 1 divided by cosine, so it has no amplitude; it has U-shaped branches that touch the cosine wave at its top and bottom and shoot off to infinity wherever cosine is 0.

In y = A*cos(Bx - C) + D, A sets the amplitude, B squeezes the period, C/B slides the graph left or right, and D moves the midline up or down. Five x values a quarter period apart give one full period: the top, the midline, the bottom, the midline, and the top again.

The formula

amplitude = |A| (cos only)

period = 2pi / |B|

phase shift = C / B (right if positive, left if negative)

midline: y = D; sec has asymptotes where cos(Bx - C) = 0

A
the amplitude for cos, or the stretch for sec; a negative A flips the graph
B
changes the period to 2pi/|B|
C
together with B, the phase shift C/B
D
the midline

Using the program

Worked example

Graph y = 3cos(2x - pi) - 1. Choose 1, then type 3 for A, 2 for B, pi for C, and -1 for D.

amplitude = 3, period = 2pi/2 = pi, phase shift = pi/2 right, midline y = -1

The program shows Amplitude: 3, Period: pi, Phase: pi/2 right, and Midline: y = -1.

The five key points are a quarter period, pi/4, apart: (pi/2, 2), (3pi/4, -1), (pi, -4), (5pi/4, -1), and (3pi/2, 2). The top is 3 above the midline and the bottom 3 below it.

Tips and common mistakes

Where this comes up

Graphing transformed cosine and secant waves, with amplitude, period, and phase shift, is part of the trigonometric graphs unit of precalculus and trigonometry.

Exact reviewed bytes

Source code

Download .py

View source below, copy it when JavaScript is available, or download the exact .py bytes.

  1. from math import sin,cos,pi
  2. def pg():input('[enter]');print('\n'*11)
  3. def val(t):
  4. t=t.lower().replace(' ','').replace('*','')
  5. if 'pi' in t:
  6. a,b=(t+'/1').split('/')[:2]
  7. a=a[:-2];a={'':'1','+':'1','-':'-1'}.get(a,a)
  8. return float(a)*pi/float(b)
  9. if '/' in t:a,b=t.split('/');return float(a)/float(b)
  10. return float(t)
  11. def ask(q,d):
  12. while 1:
  13. t=input(q+' ['+d+']: ').strip() or d
  14. try:
  15. v=val(t)
  16. if abs(v)<=1e6:return v
  17. except Exception:pass
  18. print('Like 2 or pi/3')
  19. def num(x):
  20. if abs(x-round(x))<1e-8:return str(int(round(x)))
  21. for d in range(2,33):
  22. k=round(x*d)
  23. if abs(x*d-k)<1e-8:return str(int(k))+'/'+str(d)
  24. return str(round(x,4))
  25. def rad(x):
  26. if abs(x)<1e-8:return '0'
  27. z=x/pi
  28. for d in range(1,65):
  29. k=int(round(z*d))
  30. if abs(z*d-k)<1e-8:return {1:'',-1:'-'}.get(k,str(k))+'pi'+('/'+str(d) if d>1 else '')
  31. return num(x)
  32. N=('cos','sec')
  33. def f(m,t):
  34. c=cos(t)
  35. if m==0:return c
  36. return None if abs(c)<1e-8 else 1/c
  37. def dn(m,t):return cos(t) if m else 1
  38. def draw(m,A,B,C,D,P,H,Q):
  39. try:
  40. import ti_plotlib as p
  41. lo=H-1*P/4;hi=H+5*P/4
  42. h=max(3,abs(D)+(1 if m==0 else 2.6)*max(1,abs(A))+1)
  43. p.cls();p.window(lo,hi,-h,h);p.axes('on')
  44. try:p.text_at(1,'gray=parent blue=yours','left');p.text_at(12,' '.join(rad(x) for x,y in Q),'left')
  45. except Exception:pass
  46. for k in(1,0):
  47. if k:p.color(140,140,140)
  48. else:p.color(0,0,255)
  49. o=None
  50. for i in range(91):
  51. x=lo+(hi-lo)*i/90;t=x if k else B*x-C;v=f(m,t)
  52. y=v if k or v is None else D+A*v
  53. if y is not None and abs(y)<=h:
  54. if o and dn(m,o[2])*dn(m,t)>0:p.line(o[0],o[1],x,y,'')
  55. o=(x,y,t)
  56. else:o=None
  57. p.color(255,0,0)
  58. for x,y in Q:
  59. if y is not None and -h<=y<=h:p.plot(x,y,'o')
  60. p.show_plot()
  61. except Exception as e:print('No plot:',e);pg()
  62. def facts(m,A,B,C,D,T):
  63. P=2*pi/abs(B);H=C/B;g=1 if B>0 else -1
  64. v=([1,0,-1,0,1],[1,None,-1,None,1])[m]
  65. Q=[(H+(i-0)*P/4,None if v[i] is None else D+A*v[i]) for i in range(5)]
  66. print('\n'*11);print(T)
  67. if m==0:print('Amplitude:',num(abs(A)))
  68. else:print('No amplitude\nStretch:',num(abs(A)))
  69. print('Period:',rad(P))
  70. print('Phase:',rad(abs(H)),'right' if H>0 else 'left' if H<0 else '')
  71. print('Midline: y =',num(D))
  72. if A<0:print('Flipped (A<0)')
  73. pg();print(T)
  74. for x,y in Q:print('VA: x = '+rad(x) if y is None else '('+rad(x)+', '+num(y)+')')
  75. pg();return P,H,Q
  76. print("COS + SEC GRAPHS\n __\n ___(o )> quack!\n \\ <_. )\n `---'\nDuckieDai (TM)\nhiddenwordscanner.com");pg()
  77. while 1:
  78. m=input('1 cos 2 sec 3 Exit: ').strip()
  79. if m=='3':break
  80. if m not in('1','2'):continue
  81. m=int(m)-1;print('y=A*'+N[m]+'(Bx-C)+D\n[enter] keeps default')
  82. A=ask('A','1');B=ask('B','1');C=ask('C','0');D=ask('D','0')
  83. if abs(B)<1e-6:print('B=0?');continue
  84. P,H,Q=facts(m,A,B,C,D,'YOUR GRAPH (BLUE)')
  85. facts(m,1,1,0,0,'GRAY: y='+N[m]+'(x)')
  86. if input('Draw? 1 Yes 2 No: ').strip()=='1':draw(m,A,B,C,D,P,H,Q)
  87. print('\n'*11)
Filename
TRIGCS.py
Size
2876 bytes
SHA-256
fc6bdff9d690acedfd53d92d732c3e6f28de32a49b3e695cef785aaa90db1b2f

Usage

Inputs

  • A choice: 1 cos, 2 sec, 3 exit
  • A, B, C, and D for y = A*cos(Bx - C) + D; Enter keeps the default shown

Outputs

  • The amplitude for cos or the stretch for sec, and the period, phase shift, and midline, and whether the graph is flipped
  • Five key x values over one period: points, and for sec its two vertical asymptotes
  • The same facts for the parent graph y = cos(x) or y = sec(x)
  • Optionally, a graph of both on the calculator, with the key points marked

Units: Radians; angles may be typed as multiples of pi.

Assumptions and limitations

Assumptions

  • The function is y = A*cos(Bx - C) + D or y = A*sec(Bx - C) + D, with B not 0.
  • A, B, C, and D may be decimals, fractions such as 1/2, or multiples of pi such as pi/3 or -2pi.

Constraints

  • Values are limited to -1,000,000 to 1,000,000; inf and nan are asked for again.
  • B must not be 0. A B smaller than 0.000001 is treated as 0.

Known failures

  • Answers that are not a whole number, a fraction with a denominator up to 32, or a multiple of pi up to pi/64 show 4 decimal places.
  • The graph needs the calculator's ti_plotlib module; on a computer the program shows No plot instead.

Compatibility and review

Review status
Owner-tested on a TI calculator
Tested on
Owner reports personally running this program on a TI-84 Plus CE Python calculator; the test date, OS version, and Python App version were not recorded
What happened
Owner reported pass on the calculator for the owner's original. For publication, inf, nan, and values beyond 1,000,000 are asked for again instead of stopping the program, and a B smaller than 0.000001 is treated as 0. This exact file has not yet been rerun on a calculator.
Dependencies
math, ti_plotlib
Suggested calculator name
TRIGCS — you can give it another valid, unique name when you transfer it
Desktop test cases
Not available for this interactive-only source

This exact source auto-launches an interactive calculator session, so compatibility evidence comes from the recorded physical-device review rather than an importable desktop fixture.

Transfer and launch

Download the .py file, send it to your calculator with TI Connect CE as TRIGCS or another name, then open the Python App and try the worked example on this page first. This release has no verified calculator OS or Python App version; treat transfer and execution as unverified until independently tested.

Full installation and troubleshooting guide. Check your teacher's or exam's rules before using any program.

Version history

Did a DuckieDai program help with your homework? Every program here is free. If you would like to say thanks, you can leave a tip on Cash App ($duckiedai214) or read what tips pay for.

Independent compatibility resource: Hidden Word Scanner is independent and is not affiliated with or endorsed by Texas Instruments. TI product names describe compatibility only.

Action-count privacy: Successful downloads, preview starts, and preview completions increment same-origin aggregate counters, and so does a Yes or No answer about whether the program worked. Your browser notes that you answered; that note is never sent to the site. No entered values, source text, IP address, account, cookie, device identifier, or fingerprint is stored with these counts.