Programming Challenge: a classic trigonometry problem
|
03-12-2023, 05:18 AM
Post: #36
|
|||
|
|||
RE: Programming Challenge: a classic trigonometry problem
Here is an interesting symmetric pair of q guesses, derived at the same time.
1/v = 1/c - 1/u Remember v is positive, but u can be both (u has sign of q): edge(u) = ±a Let z = c/a edge(1/v) = 1/c ± 1/a = (1 ± c/a) / c edge(v/c) = (1 ± z)^-1 u = ±√(a² - y) = ±√(a² - (b² - v²)) = c * (1 + q) (1 + q) = ±√((a²-b²)/c² + (v/c)²) edge(q) = -(1 ± √(k + (1±z)^-2)) We redo previous post example, solve for both Q real roots. I named negative q guess as "hi", only because it is bigger in size. lua> S = require'solver' lua> a, b, c = 40, 30, 15 lua> k = (a*a-b*b)/(c*c) lua> Q = fn'q: (1+q)^2*(1-q^-2) - k' lua> eps = -1e-9 -- swap worse point as first lua> z = c/a lua> lo = -(1 - sqrt(k + (1-z)^-2)) -- positive q guess lua> hi = -(1 + sqrt(k + (1+z)^-2)) -- negative q guess lua> S.secant(Q, lo, lo*1.01, eps, true) 1.3814094799322336 -- = lo 1.395223574731556 1.4441708057247238 1.4443988616014456 1.4443995665095293 1.4443995665182763 lua> S.secant(Q, hi*0.99, hi, eps, true) -2.907888028932993 -- = hi -2.878809148643663 -2.8807700072753484 -2.8807853577712663 -2.8807853490168784 -2.880785349016917 -2.880785349016917 |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)