Exemple #1
0
def tangent_line(f, x_):
    d = numerical_diff(f, x_)
    print("d")
    print(d)
    y = f(x_) - d*x_      # xの位置で元の数式に接するようにx時点の値を算出
    print("y")
    print(y)
    return lambda t: d*t + y
Exemple #2
0
import numpy as np
import matplotlib.pylab as plt
from numerical_diff import numerical_diff


def function_1(x):
    return 0.01 * x**2 + 0.1 * x


print(numerical_diff(function_1, 5))
print(numerical_diff(function_1, 10))

x = np.arange(0.0, 20.0, 0.1)
y = function_1(x)
plt.xlabel("x")
plt.xlabel("f(x)")
plt.plot(x, y)
plt.show()
Exemple #3
0
def tangent_line(f, x):
    d = numerical_diff(f, x)
    print(d)
    y = f(x) - d*x
    return lambda t: d*t + y
Exemple #4
0
import numpy as np

import matplotlib.pylab as plt

from mpl_toolkits.mplot3d import Axes3D

if __name__ == '__main__':

    x = np.arange(0.0, 20, 0.01)
    x1 = np.arange(0.0, 20, 0.01)
    y = function_1(x)
    plt.xlabel("x")
    plt.ylabel("f(x)")
    plt.plot(x, y)
    plt.show()

    import numerical_diff as nd
    #0.2 0.3
    print(nd.numerical_diff(function_1, 5))
    print(nd.numerical_diff(function_1, 10))

    print(nd.origin_numerical_diff(function_1, 5))
    print(nd.origin_numerical_diff(function_1, 10))

    y = nd.numerical_diff(function_1, x)
    plt.plot(x, y)
    plt.show()
    y = nd.origin_numerical_diff(function_1, x)
    plt.plot(x, y)
    plt.show()
Exemple #5
0
from numerical_diff import numerical_diff


def function_2(x):
    return x[0]**2 + x[1]**2


#x0 =3, x1=4
def function_tmp1(x0):
    return x0 * x0 + 4.0**2.0


#x0 =3, x1=4のx0に対する偏微分
print(numerical_diff(function_tmp1, 3.0))


def function_tmp2(x1):
    return 3.0**2.0 + x1 * x1


#x0 =3, x1=4のx0に対する偏微分
print(numerical_diff(function_tmp2, 4.0))