| Deutsch English Français Italiano |
|
<87tte941ko.fsf@nightsong.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Paul Rubin <no.email@nospam.invalid>
Newsgroups: comp.lang.python
Subject: Re: Beazley's Problem
Date: Sat, 21 Sep 2024 05:45:59 -0700
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <87tte941ko.fsf@nightsong.com>
References: <problem-20240921130726@ram.dialup.fu-berlin.de>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Sat, 21 Sep 2024 14:46:00 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="e94199ffdbd21758a00d3c67b53911fe";
logging-data="1689580"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+J8h+JXY4Y59/SVt5tfXfP"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:YxZq7BtGtX0Gsb569loqP5XlhOs=
sha1:mbH4Etd7anjlh+h/bK0goxc90OQ=
Bytes: 2006
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)