package org.mariuszgromada.math.mxparser.mathspace; import org.mariuszgromada.math.mxparser.*; import org.mariuszgromada.math.mxparser.mathcollection.*; public class PlayingWithRecursionPart4 { public static void main(String[] args) { /* Definicja funkcji rekurencyjncyh */ Constant a = new Constant("a", 0.01); Function s = new Function("s", "if( abs(x) < a, x, 2*s(x/2)*c(x/2) )", "x"); s.setRecursiveMode(); Function c = new Function("c", "if( abs(x) < a, 1, c(x/2)^2-s(x/2)^2 )", "x"); c.setRecursiveMode(); /* Dodanie do definicji funkcji stalej 'a' */ s.addConstants(a); c.addConstants(a); /* Wskazanie, ze 's' korzysta z 'c', a 'c' korzysta z 's' */ s.addFunctions(c); c.addFunctions(s); /* Dane do wykresu s(x) vs sin(x) */ for (double x = -MathConstants.PI; x <= MathConstants.PI; x=x+0.02) mXparser.consolePrintln("[ " + x +", " + MathFunctions.sin(x) + ", " + s.calculate(x) + " ],"); /* Dane do wykresu c(x) vs cos(x) */ for (double x = -MathConstants.PI; x <= MathConstants.PI; x=x+0.02) mXparser.consolePrintln("[ " + x +", " + MathFunctions.cos(x) + ", " + c.calculate(x) + " ],"); } }