Пример #1
0
def in3(number):
    t = sp.symbols('t')
    if number == 1:
        p0 = 1.5  # The interval, it's suppose that a < b
        f = t**2 - 3  # The function
        tol = 1e-5  # The max error acceptable
        nmax = 10  # Max number iteractions
    elif number == 2:
        p0 = 3  # The interval, it's suppose that a < b
        f = t**2 - 2 * t - 4  # The function
        tol = 1e-5  # The max error acceptable
        nmax = 10  # Max number iteractions
    elif number == 3:
        p0 = 1.5  # The interval, it's suppose that a < b
        f = t**3 + 4 * t**2 - 10  # The function
        tol = 1e-5  # The max error acceptable
        nmax = 10  # Max number iteractions

    f_ = sp.diff(f, t)  # The function f' derivative of f

    # The begin to start the calculations
    feval = sp.lambdify(t, f, "numpy")
    flatex = "$f(t) = " + aux.toLaTeX(f)
    f = aux.Funcao(feval, flatex)

    f_eval = sp.lambdify(t, f_, "numpy")
    f_latex = "$f'(t) = " + aux.toLaTeX(f_)
    f_ = aux.Funcao(f_eval, f_latex)

    return p0, f, f_, tol, nmax
Пример #2
0
def in2(number):
    f, t, x = master(number)
    f_ = sp.diff(f, t)
    feval = sp.lambdify(t, f, "numpy")  # Transform the function to lambdify
    flatex = "$f(t) = " + aux.toLaTeX(f)
    f_eval = sp.lambdify(t, f_, "numpy")  # Transform the function to lambdify
    f_latex = "$f'(t) = " + aux.toLaTeX(f_)
    f = aux.Funcao(feval, flatex)
    f_ = aux.Funcao(f_eval, f_latex)
    y = f.e(x)
    y_ = f_.e(x)
    return x, y, y_, f, f_
Пример #3
0
def in1(number):
    f, t, x = master(number)
    feval = sp.lambdify(t, f, "numpy")  # Transform the function to lambdify
    flatex = "$f(t) = " + aux.toLaTeX(f)
    f = aux.Funcao(feval, flatex)
    y = f.e(x)
    return x, y, f  # x e y são arrays, que indicam os pontos
Пример #4
0
def in10(number):
    f, t, x = master(number)
    f_ = sp.diff(f, t)
    f_ = sp.lambdify(t, f_, "numpy")
    FP = np.array((f_(x[0]), f_(x[-1])))

    feval = sp.lambdify(t, f, "numpy")  # Transform the function to lambdify
    flatex = "$f(t) = " + aux.toLaTeX(f)
    f = aux.Funcao(feval, flatex)
    y = f.e(x)
    return x, y, f, FP
Пример #5
0
def in2(number):
    t = sp.symbols('t')
    if 1 <= number <= 5:
        p0 = 1.5  # The initial aproximation
        f = t**3 + 4 * t**2 - 10  # The function that we want to calculate the roots
        tol = 1e-5  # The max error acceptable
        nmax = 10  # Max number iteractions
        if number == 1:
            g = t - t**3 - 4 * t**2 + 10  # It doesn't converg
        elif number == 2:
            g = sp.sqrt(4 * t - 10 / t)  # It doesn't converg
        elif number == 3:
            g = sp.sqrt(
                10 - t**3
            ) / 2  # The fixed point function, using f(x) = 0 we can get x = sqrt(10-x**3)/2
        elif number == 4:
            g = sp.sqrt(10 / (4 + t))  # It converges quite well
        elif number == 5:
            g = t - (t**3 + 4 * t**2 - 10) / (
                3 * t**2 + 8 * t
            )  # It converges very well, we will see this funcion in the Newton's method

    g_ = sp.diff(g, t)  # The function g' derivative of g

    feval = sp.lambdify(t, f, "numpy")
    flatex = "$f(t) = " + aux.toLaTeX(f)
    f = aux.Funcao(feval, flatex)

    geval = sp.lambdify(t, g, "numpy")
    glatex = "$g(t) = " + aux.toLaTeX(g)
    g = aux.Funcao(geval, glatex)

    g_eval = sp.lambdify(t, g_, "numpy")
    g_latex = "$g'(t) = " + aux.toLaTeX(g_)
    g_ = aux.Funcao(g_eval, g_latex)

    return p0, f, g, g_, tol, nmax
Пример #6
0
def Lagrange(x, y):
	# The variables
	t 		= sp.symbols('t')

	# The calculations
	n = len(x)
	L = []
	for i in range(n):
		Li = 1
		for j in range(n):
			if i != j:
				Li *= (t-x[j])/(x[i]-x[j])
		L.append(Li)
	g = 0
	for i in range(n):
		g += L[i] * y[i]
	g = sp.simplify(g)
	L = aux.Funcao(sp.lambdify(t, g, "numpy"), '$L(t) = ' + aux.toLaTeX(g))
	return L
Пример #7
0
def in1(number):
    t = sp.symbols('t')
    if number == 1:
        a, b = 1, 2  # The interval, it's suppose that a < b
        f = t**2 - 3  # The function
        tol = 1e-5  # The max error acceptable
        nmax = 10  # Max number iteractions
    elif number == 2:
        a, b = 2, 4  # The interval, it's suppose that a < b
        f = t**2 - 2 * t - 4  # The function
        tol = 1e-5  # The max error acceptable
        nmax = 10  # Max number iteractions
    elif number == 3:
        a, b = 1, 2  # The interval, it's suppose that a < b
        f = t**3 + 4 * t**2 - 10  # The function
        tol = 1e-5  # The max error acceptable
        nmax = 10  # Max number iteractions

    # The begin to start the calculations
    feval = sp.lambdify(t, f, "numpy")
    flatex = "$f(t) = " + aux.toLaTeX(f)
    f = aux.Funcao(feval, flatex)
    return a, b, f, tol, nmax
Пример #8
0
def in1(number):
	f, t, a, b, n = master(number)
	feval	= sp.lambdify(t, f, "numpy")
	flatex	= "$f(t) = " + aux.toLaTeX(f)
	f		= aux.Funcao(feval, flatex)
	return a, b, n, f