Created
April 24, 2022 13:43
-
-
Save rzrn/0bcfd6458665fe87baad012a618a9211 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dataclasses import dataclass | |
from random import random | |
@dataclass | |
class Vector: | |
x : float | |
y : float | |
def __sub__(v1, v2): | |
return Vector(v1.x - v2.x, v1.y - v2.y) | |
def norm(v): | |
return v.x * v.x + v.y * v.y | |
N = 5 | |
params, vs = [], [] | |
for idx in range(N): | |
vs.append(Vector(random(), random())) | |
params.append(random()) | |
def g(n, v0): | |
z = 1 | |
for (k, v) in enumerate(vs): | |
if k != n: | |
z *= (v - v0).norm() / (v - vs[n]).norm() | |
return z | |
f = lambda v: sum(map(lambda k: params[k] * g(k, v), range(N))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment