eQuate It CAS UDFs — Functions (TI-Nspire CAS) ================================================ 1. asymp(f, x) — Vertical and horizontal asymptotes ------------------------------------------------------- Define asymp(f, x) = Prgm Local va, ha, denom_expr, num_expr, lp, ln va := {} ha := {} denom_expr := getDenom(f) If denom_expr ≠ 1 Then va := solve(denom_expr = 0, x) EndIf lp := limit(f, x, ∞) ln := limit(f, x, -∞) If lp ≠ ∞ and lp ≠ -∞ and lp ≠ undef Then ha := augment(ha, {lp}) EndIf If ln ≠ ∞ and ln ≠ -∞ and ln ≠ undef and ln ≠ lp Then ha := augment(ha, {ln}) EndIf Disp "Vertical: ", va Disp "Horizontal: ", ha EndPrgm 2. ccheck(f, g) — Composite function check ------------------------------------------------------- Define ccheck(f, g) = Prgm Local dom_f, ran_g, result Disp "f(g(x)) composite check" result := f(g(x)) If result ≠ undef Then Disp "Composite exists: ", result Else Disp "Composite does not exist over full domain" Disp "Restrict domain of g so range(g) ⊆ domain(f)" EndIf EndPrgm 3. discrim(expr, x, dp) — Discriminant of a quadratic ------------------------------------------------------- Define discrim(expr, x, dp) = Prgm Local a, b, c, d a := polyCoeffs(expr, x)[1] b := polyCoeffs(expr, x)[2] c := polyCoeffs(expr, x)[3] d := b^2 - 4*a*c Disp "a = ", a Disp "b = ", b Disp "c = ", c Disp "Discriminant = ", round(d, dp) If d > 0 Then Disp "Two distinct real roots" ElseIf d = 0 Then Disp "One repeated real root" Else Disp "No real roots" EndIf EndPrgm 4. domrang(f, x) — Domain and range ------------------------------------------------------- Define domrang(f, x) = Prgm Local dom, ran dom := domain(f, x) ran := range(f, x) Disp "Domain: ", dom Disp "Range: ", ran EndPrgm 5. intercepts(f, x) — X and Y intercepts ------------------------------------------------------- Define intercepts(f, x) = Prgm Local xi, yi xi := solve(f = 0, x) yi := f | x = 0 Disp "x-intercepts: ", xi Disp "y-intercept: ", yi EndPrgm 6. intersects(f1, f2, x) — Points of intersection ------------------------------------------------------- Define intersects(f1, f2, x) = Prgm Local pts, xvals, i xvals := solve(f1 = f2, x) Disp "Intersection x-values: ", xvals Disp "Points:" For i, 1, dim(xvals) Disp "(", xvals[i], ", ", f1 | x = xvals[i], ")" EndFor EndPrgm 7. intersectsd(f1, f2, x, lo, hi) — Intersections in restricted domain ------------------------------------------------------- Define intersectsd(f1, f2, x, lo, hi) = Prgm Local xvals xvals := solve(f1 = f2, x) | lo ≤ x ≤ hi Disp "Intersections in [", lo, ",", hi, "]:" Disp xvals EndPrgm 8. inverse(f, x, x0) — Inverse function ------------------------------------------------------- Define inverse(f, x, x0) = Prgm Local y, inv_expr inv_expr := solve(y = f, x) Disp "Inverse: x = ", inv_expr If x0 ≠ undef Then Disp "At x =", x0, ": ", inv_expr | y = x0 EndIf EndPrgm 9. invints(f, n) — Inverse intersections with parameter k ------------------------------------------------------- Define invints(f, n) = Prgm Local inv_f, eq, result Disp "Finding k for ", n, " intersections with inverse" inv_f := solve(y = f, x) eq := solve(f = inv_f, x) Disp "Solve for parameter to get ", n, " solutions" Disp eq EndPrgm 10. lineang(l1, l2, x) — Angle between two lines ------------------------------------------------------- Define lineang(l1, l2, x) = Prgm Local m1, m2, theta m1 := d(l1, x) m2 := d(l2, x) theta := arctan(abs((m1 - m2)/(1 + m1*m2))) Disp "Gradient 1: ", m1 Disp "Gradient 2: ", m2 Disp "Angle (rad): ", theta Disp "Angle (exact): ", theta EndPrgm 11. linesolve(eq1, eq2) — Unique/None/Infinite solutions ------------------------------------------------------- Define linesolve(eq1, eq2) = Prgm Local result result := solve(eq1 and eq2, {x, y}) If dim(result) = 0 Then Disp "No solution (inconsistent)" ElseIf string(result) contains "=" Then Disp "Unique solution: ", result Else Disp "Infinitely many solutions" Disp result EndIf EndPrgm 12. pcheck(f, x, lhs, rhs) — Property check ------------------------------------------------------- Define pcheck(f, x, lhs, rhs) = Prgm Local test test := expand(lhs - rhs) If test = 0 Then Disp "Property satisfied: TRUE" Else Disp "Property NOT satisfied" Disp "LHS - RHS = ", test EndIf EndPrgm 13. pointinfo(x1, y1, x2, y2) — Complete line information ------------------------------------------------------- Define pointinfo(x1, y1, x2, y2) = Prgm Local m, mp, eq, xi, yi, mid, dist m := (y2 - y1)/(x2 - x1) mp := -1/m eq := m*(x - x1) + y1 xi := solve(eq = 0, x) yi := eq | x = 0 mid := {(x1 + x2)/2, (y1 + y2)/2} dist := sqrt((x2 - x1)^2 + (y2 - y1)^2) Disp "Gradient: ", m Disp "Perp gradient: ", mp Disp "Equation: y = ", eq Disp "x-intercept: ", xi Disp "y-intercept: ", yi Disp "Midpoint: ", mid Disp "Distance: ", dist EndPrgm 14. polyfit(pts) — Polynomial through points ------------------------------------------------------- Define polyfit(pts) = Prgm Local n, i, xv, yv, coeffs, poly, vars n := dim(pts)/2 xv := seq(pts[2*i - 1], i, 1, n) yv := seq(pts[2*i], i, 1, n) coeffs := seq(a[i], i, 0, n - 1) poly := sum(seq(coeffs[i + 1]*x^i, i, 0, n - 1)) vars := seq(a[i], i, 0, n - 1) result := solve(seq(poly | x = xv[i]) = yv[i], i, 1, n), vars) Disp "Polynomial: ", poly | result EndPrgm 15. transform(f, trans) — Apply transformations ------------------------------------------------------- Define transform(f, trans) = Prgm Local result, i, t result := f For i, 1, dim(trans) t := trans[i] result := result | x = t EndFor Disp "Transformed: ", result EndPrgm 16. transolve(orig, image, x) — Find transformations ------------------------------------------------------- Define transolve(orig, image, x) = Prgm Local a, b, c, d, result Disp "Finding transformations: original -> image" result := solve(a*orig(b*x + c) + d = image, {a, b, c, d}) Disp "Transformations: ", result EndPrgm 17. bisec(f, x, lo, hi, n) — Bisection method ------------------------------------------------------- Define bisec(f, x, lo, hi, n) = Prgm Local a, b, mid, i, fa, fb, fm a := lo b := hi For i, 1, n mid := (a + b)/2 fa := f | x = a fm := f | x = mid If fa * fm < 0 Then b := mid Else a := mid EndIf Disp "Iteration ", i, ": x = ", approx(mid) EndFor Disp "Root approx: ", approx((a + b)/2) EndPrgm