SharedSYSTEM_URAVN_V2.0.ipynbOpen in CoCalc
import pandas as pd
import numpy as np
from scipy import optimize, linalg
import scipy
from scipy import spatial
import re
import math
import pandas as pd
from numpy import zeros, dot, savetxt
import matplotlib
from matplotlib import pylab as plt
%matplotlib inline
import numpy as np
index = 0
chetchik = 0
matriza_vvoda = []
work_m = []
znach_func = []
print 'vvodite po 2 chisla'
while index == 0:                    #ввод значений
    matriza_vvoda += [raw_input().split(' ')]
    last = matriza_vvoda.pop()
    if last == ['end']:
        index = 1
    else:
        matriza_vvoda += [last]
for j in range(len(matriza_vvoda)):             #перевод в действительные
    for i in range(len(matriza_vvoda[j])):
        matriza_vvoda[j][i] = float(matriza_vvoda[j][i])
for i in range(len(matriza_vvoda)):             #создание списка значений функции
        znach_func += [matriza_vvoda[i].pop()]
for k in range(len(matriza_vvoda)):             #из матрицы в список-2
    work_m += [matriza_vvoda[k][0]]
for i in range(len(work_m)):            #из списка в матрицу
    work_m[i] = [work_m[i]]
for i in range(len(work_m)):            #умножения количества элементов 
    work_m[i] = work_m[i] * (len(work_m))
N = 0
for i in range(len(work_m)):            #создание матрицы квадратов
    for j in range(len(work_m)):
        work_m[i][j] = work_m[i][j] ** N
        N += 1
    N = 0
koeff = np.linalg.solve(work_m, znach_func) #Находим решение системы
print koeff
vvodite po 2 chisla
[ 1. -4.41666667 4.125 -0.70833333]
print matriza_vvoda,'\n', work_m,'\n',znach_func
[[2.0], [1.0], [0.0], [4.0]] [[1.0, 2.0, 4.0, 8.0], [1.0, 1.0, 1.0, 1.0], [1.0, 0.0, 0.0, 0.0], [1.0, 4.0, 16.0, 64.0]] [3.0, 0.0, 1.0, 4.0]
def Polin_func2(vector, koeff = koeff):              #функция нахождения полинома
    znach_v = []
    shab = []
    for znach in vector:
        for i in range(len(koeff)):
            shab += [koeff[i] * (znach ** i)]
        znach_v += [float(sum(shab))]
        shab = []
    return znach_v

koeff
a = np.linspace(-6, 10, num = 1000)
b = Polin_func2(a)
plt.plot(b)
plt.show
<function matplotlib.pyplot.show>
python WORK2_POLINOM_V.py
File "<ipython-input-3-96baadb3f3dc>", line 1 python WORK2_POLINOM_V.py ^ SyntaxError: invalid syntax