Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #196738
| From | Paul Rubin <no.email@nospam.invalid> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Beazley's Problem |
| Date | 2024-09-21 05:45 -0700 |
| Organization | A noiseless patient Spider |
| Message-ID | <87tte941ko.fsf@nightsong.com> (permalink) |
| References | <problem-20240921130726@ram.dialup.fu-berlin.de> |
ram@zedat.fu-berlin.de (Stefan Ram) writes:
> Alright, so here's how I approached it: We know that when the
> price x is 5 bucks, the number of people n is 120 (^1).
That assumption doesn't seem so good, but accepting it, your answer
looks right. Here is a pure numerical solution. Since the profit
function is quadratic, the Newton iteration converges immediately.
================================================================
def cost(n): return 180+.04*n # cost to show to n viewers
def revenue(price,n): return price*n # amount collected from them
def people(price): return 120.+(price-5)*(-15./.1) # number who will attend
def profit(price):
n = people(price)
return revenue(price,n) - cost(n)
def ddx(f,x,h=0.001): return (f(x+h)-f(x-h))/(2*h) # numerical derivative
def newton(f,x0): return x0 - f(x0)/ddx(f,x0) # Newton-Raphson iteration
def dprofit(price): return ddx(profit, price) # derivative of profit
x = 5.
for i in range(3):
print(f'{i} {x:.4f} {profit(x):.1f} {dprofit(x):.1f}')
x = newton(dprofit,x)
Back to comp.lang.python | Previous | Next — Next in thread | Find similar
Re: Beazley's Problem Paul Rubin <no.email@nospam.invalid> - 2024-09-21 05:45 -0700
Re: Beazley's Problem Paul Rubin <no.email@nospam.invalid> - 2024-09-21 13:19 -0700
Re: Beazley's Problem Annada Behera <annada@tilde.green> - 2024-09-23 13:14 +0530
Re: Beazley's Problem (Posting On Python-List Prohibited) Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-09-23 22:44 +0000
Re: Beazley's Problem Paul Rubin <no.email@nospam.invalid> - 2024-09-23 17:22 -0700
Re: Beazley's Problem Annada Behera <annada@tilde.green> - 2024-09-24 13:55 +0530
Re: Beazley's Problem dkcombs@panix.com (david k. combs) - 2024-11-10 20:48 +0000
Re: Beazley's Problem Paul Rubin <no.email@nospam.invalid> - 2024-11-10 13:55 -0800
Re: Modern Optimization (was: Beazley's Problem) Gilmeh Serda <gilmeh.serda@nothing.here.invalid> - 2024-09-26 16:13 +0000
Re: Beazley's Problem Antoon Pardon <antoon.pardon@vub.be> - 2024-10-06 22:19 +0200
csiph-web