Re: Beazley's Problem

Liste des GroupesRevenir à cl python 
Sujet : Re: Beazley's Problem
De : no.email (at) *nospam* nospam.invalid (Paul Rubin)
Groupes : comp.lang.python
Date : 21. Sep 2024, 14:45:59
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <87tte941ko.fsf@nightsong.com>
References : 1
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
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)

Date Sujet#  Auteur
21 Sep 24 * Beazley's Problem14Stefan Ram
21 Sep 24 `* Re: Beazley's Problem13Paul Rubin
21 Sep 24  `* Re: Beazley's Problem12Stefan Ram
21 Sep 24   `* Re: Beazley's Problem11Paul Rubin
23 Sep 24    `* Re: Beazley's Problem10Annada Behera
23 Sep 24     +* Re: Beazley's Problem8Stefan Ram
24 Sep 24     i+- Re: Beazley's Problem (Posting On Python-List Prohibited)1Lawrence D'Oliveiro
24 Sep 24     i+* Re: Beazley's Problem4Paul Rubin
24 Sep 24     ii+- Re: Beazley's Problem1Annada Behera
10 Nov22:48     ii`* Re: Beazley's Problem2david k. combs
10 Nov23:55     ii `- Re: Beazley's Problem1Paul Rubin
26 Sep 24     i`* Modern Optimization (was: Beazley's Problem)2Stefan Ram
26 Sep 24     i `- Re: Modern Optimization1Stefan Ram
6 Oct 24     `- Re: Beazley's Problem1Antoon Pardon

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal