Python Forum
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Calculus in python
#11
"Average value of curve" on wolframalpha is calculated as definite integral of function on interval[A, B] divided by length of that interval (that is B - A). So in this case resulting definite integral must be divided by (b - 1).
Reply
#12
Awesome!

integrate.quad(lambda x: ((a*b/c) * 1.05**(-x))/(b-1), 1, b)

Even better is that you pointed out I don't need to use calculus at all:

(-(a*b/c) / math.log(1.05) * ( 1.05**-b - 1.05**-a ))/(b-1)

Thank you for your help!
Reply
#13
I'm running into division by zero when b=1.  This formula works in that case:

a / ( c * 1.05 )

But is there any way to gracefully use the same formula regardless of the value of b?  I'm working in the pyspread python spreadsheet so I'm trying to use one-liners.
Reply
#14
What about just special-casing it? 0 if not b else (formula)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Some help with some calculus and fish agritheory 4 3,178 Aug-17-2018, 07:40 PM
Last Post: agritheory

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020