finding if a function has positive values in a given range

185 Views Asked by At

Context:trying to find a NEW fast way to factorize very big numbers using binary search

So I have a function:

$f\left(x\right)=\left(\cos\left(\pi x\right)^2+\cos\left(\frac{n\pi}{x}\right)^2\right)^k-1.99^k$

when this function is greater than 0 , x is a factor of n.(most of the times, depends on how big k is) Originally the 1.99 part is replaced with 2 and the function will be 0 only when x is factor of n, but there isn't much I can do with that.

So I recently thought about changing it slightly so the function will be positive when x is a factor of n, so that after using a "if x<0, f(x)=0" function i could calculate the integral of the function between two points, if it is higher than 0 that means a factor is in range and so I could cut the range in half and iterate this until I find x. however, when I do try to this as shown here: https://www.desmos.com/calculator/6badnevuyv

when n=14, a & b (the range) is 4-8, the function(integral that uses f4) returns 0 although it should return a greater number

why isn't it working and is there a better way to actually check if a function is positive within a given range? or perhaps if n have factors in a given range

1

There are 1 best solutions below

2
On

I don't know for sure, but it is likely that you've exceeded Desmos's ability to calculate integrals accurately. Your method appears to have very low computational stability.

I would recommend a simpler approach. How about just using Newton's method to find roots of $$\cos\left(\pi x\right)^2+\cos\left(\frac{n\pi}{x}\right)^2-2?$$

Though for that idea, it would be much better to find a curve that crosses $0$ at a slope near $\pm1$ than one that comes in tangent.