def newtonRaphson(x):
    xList = []
    yList = []
    while True:
        xList.append(x)
        yList.append(f(x))
        if f(x) == 0.0:
            break
        x = x - f(x) / df(x)
    dframe = dfr()
    dframe["x"] = xList
    dframe["f(x)"] = yList
    print(dframe)
    print("The value of root is:", x)
Пример #2
0
    listb.append(b)
    listx0.append(c)
    listfx0.append(d)


def bisectionMethod(a, b):
    if f(a) * f(b) > 0.0:
        print("Choose alternate value of a and b.")
    else:
        while f(a) * f(b) < 0.0:
            c = (a + b) / 2
            table(a, b, c, round(f(c), 4))
            if f(c) == 0.0:
                break
            elif f(c) * f(a) < 0.0:
                b = c
            else:
                a = c
    print("The value of root is:", c)


a = 0.5
b = 1.0
bisectionMethod(a, b)
dfr = dfr()
dfr['a'] = lista
dfr['b'] = listb
dfr['x0'] = listx0
dfr['f(x0)'] = listfx0
print(dfr)
Пример #3
0
from pandas import DataFrame as dfr
import matplotlib.pyplot as plt


def f(x):
    if x == 0:
        return 0
    elif x == 1:
        return 0
    else:
        return x**2 - 64 * x + 10


xi = nmp.arange(0, 1.1, 0.1)
h = 0.1
yi = list()
yi.append(0)
for i in xi[1:-1]:
    y = (f(i + h) - 2 * f(i) + f(i - h)) / h**2
    yi.append(y)
yi.append(0)
df = dfr()
df["xi"] = xi
df["yi"] = yi
print(df)
plt.plot(xi, yi)
plt.title(
    '''Finite different method plot of 2nd order method plot of y"-64y'+10=0'''
)
plt.show()
Пример #4
0
import numpy as nmp
from math import e
from pandas import DataFrame as dfr

data = nmp.linspace(-1, 1, 19)
x_value = nmp.around(data, decimals=3)
count = (len(x_value))
table = nmp.zeros((count, count))
y_value = []
for i in x_value:
    y_value.append(nmp.around((e**i), decimals=3))
table[:, 0] = y_value
for i in range(1, count):
    for j in range(count - i):
        table[j][i] = nmp.around(table[j + 1][i - 1] - table[j][i - 1], 3)
print(
    dfr(table, x_value, [
        "y", "△y1", "△y2", "△y3", "△y4", "△y5", "△y6", "△y7", "△y8", "△y9",
        "△y10", "△y11", "△y12", "△y13", "△y14", "△y15", "△y16", "△y17", "△y18"
    ]))