Make a table of values in phyton [closed]

0

Hi, I have a problem I would like to know how to make a formula that prints a table of values of a linear function with while?

    
asked by Ignacio 04.09.2017 в 23:04
source

1 answer

-1

I think you understand what you mean, do you want to print a graph from a linear function? If so, I recommend using Matplotlib since it is a fairly complete library that allows you to make graphs from values.

Here is an example of how to graph a linear function and a quadratic with it.

#!/usr/bin/env python
**

# -*- coding: utf-8 -*-
    from matplotlib import pyplot
    # Función cuadrática.
    def f1(x):
        return 2*(x**2) + 5*x - 2
    # Función lineal.
    def f2(x):
        return 4*x + 1
    # Valores del eje X que toma el gráfico.
    x = range(-10, 15)
    # Graficar ambas funciones.
    pyplot.plot(x, [f1(i) for i in x])
    pyplot.plot(x, [f2(i) for i in x])
    # Establecer el color de los ejes.
    pyplot.axhline(0, color="black")
    pyplot.axvline(0, color="black")
    # Limitar los valores de los ejes.
    pyplot.xlim(-10, 10)
    pyplot.ylim(-10, 10)
    # Guardar gráfico como imágen PNG.
    pyplot.savefig("output.png")
    # Mostrarlo.
    pyplot.show()

**

    
answered by 04.09.2017 / 23:54
source