#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Sep  3 14:00:05 2024

@author: sam
"""

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(-3,3) #generate values from -3 to 3

a = np.array([[-1],[0],[1],[2]]) #create array of values for function



def f(x):
    return 1 - 2*x + x**2

def polyx(a,x):
    f = 0
    for i in range(len(a)):
        f += a[i]*(x)**i #increases f by array element i times x to the power of i
                         #i.e. first term (a0)(x0)^0 = a0
    return f



f = polyx(a,x)
plt.plot(x,f)