0

If I were to run something like the code below where I pass in the minor and major arc of an ellipse as 3.05 and 2.23 with the 50 degree angle formed by the arc, how would I be able to take the output of 2.531432761012828 as the arc length and pass it back through to solve for t? Thanks!

import math
from scipy.integrate import quad
import numpy as np
t = math.atan(3.05*math.tan(5*math.pi/18)/2.23)
Dx = lambda t: -3.05 * np.sin(t)   
Dy = lambda t: 2.23 * np.cos(t)
quad(lambda t: np.sqrt(Dx(t)**2 + Dy(t)**2), 0, t)

The output of the last one was: (2.531432761012828, 2.810454936566873e-14)

Fairly Factual
  • 161
  • 3
  • 13
  • Have you tried `full_output`? With analytical integration, can you 'backout' the upper integration limit from the value? – hpaulj Jul 07 '17 at 20:32

1 Answers1

2

To find the upper limit of integration, given the value of the integral, one can apply fsolve to the function which calculates that integral for variable upper limits. Example (not repeating the lines you already have):

from scipy.optimize import fsolve
target = 2.531432761012828
fun = lambda s: quad(lambda t: np.sqrt(Dx(t)**2 + Dy(t)**2), 0, s)[0] - target
s0 = fsolve(fun, 0)[0]
print(s0) 

This prints 1.02051.

I dislike having both the variable of integration and the upper limit denoted by the same letter, so in my code the upper limit is called s.

  • In a crude sense the tries various upper limit values in the vicinity of your initial guess until it finds one that produces the same integral. It's more sophisticated than a hunt-n-peck, but the principal is the same. Try values until you get a match. – hpaulj Jul 08 '17 at 00:51