🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.python
Article #27544

Re: Interpolacja Liniowa

#27544
From: Bart Ogryczak
Date: Mon, 28 Jun 2010 16:49
25 lines
2062 bytes
On Jun 26, 8:41 pm, rav <rafalgulin...@gmail.com> wrote:
> Nie dziala kiedy x2-x1 == 0 (div by zero)
> dlatego dodalbym sprawdzenie roznicy tych wartosci do funkcji
>
> def getInterpolated(x0,y0, x1, y1):
>     if x1 - x0 == 0:
>         print 'x1 i x0 can\'t be equal'
>         return None
>     a = (y1 - y0) / (x1 - x0)
>     b = y0 - a * x0
>     def interpolate(x):
>         return a * x + b
>     return None

Pythonistycznie, to raczej będzie tak:

try:
    a = (y2 - y1) / (x2 - x1)
    b = ((-x1) * (y2 - y1) - (x2 - x1) * (-y1)) / (x2 - x1)
    def interpolate(x):
        return a * x + b
    return interpolate
except ZeroDivisionError:
    print 'x1 i x0 can\'t be equal'
    return None
Technical Details
Message-ID: <031bca8d-171b-4d28-beb8-f64b45568212@r27g2000yqb.googlegroups.com>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!newsfeed.pionier.net.pl!news-2.dfn.de!news.dfn.de!feeder.erje.net!feeder.news-service.com!postnews.google.com!r27g2000yqb.googlegroups.com!not-for-mail
References: <76da39d8-1875-4b7e-b66b-a1ef32499279@u26g2000yqu.googlegroups.com> <i035le$ioj$1@news.onet.pl> <b189acfc-d1de-4cb3-8831-4e11e3d87054@d8g2000yqf.googlegroups.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!newsfeed.pionier.net.pl!news-2.dfn.de!news.dfn.de!feeder.erje.net!feeder.news-service.com!postnews.google.com!r27g2000yqb.googlegroups.com!not-for-mail
From: Bart Ogryczak <b.ogryczak@gmail.com>
Newsgroups: pl.comp.lang.python
Subject: Re: Interpolacja Liniowa
Date: Mon, 28 Jun 2010 09:49:06 -0700 (PDT)
Organization: http://groups.google.com
Lines: 25
Message-ID: <031bca8d-171b-4d28-beb8-f64b45568212@r27g2000yqb.googlegroups.com>
References: <76da39d8-1875-4b7e-b66b-a1ef32499279@u26g2000yqu.googlegroups.com>  <i035le$ioj$1@news.onet.pl> <b189acfc-d1de-4cb3-8831-4e11e3d87054@d8g2000yqf.googlegroups.com>
NNTP-Posting-Host: 94.100.112.225
Mime-Version: 1.0
X-Trace: posting.google.com 1277743746 18325 127.0.0.1 (28 Jun 2010 16:49:06 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Mon, 28 Jun 2010 16:49:06 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: r27g2000yqb.googlegroups.com; posting-host=94.100.112.225;  posting-account=1kG_1AoAAADLEA3eucGvO2J-Uo4aPCW_
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US)  AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.86 Safari/533.4,gzip(gfe)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit