SmtC: Show me the Code
Ole Peter Smith
Instituto de Matemática e Estatística
Universidade Federal de Goiás
http://www.olesmith.com.br

Polinômios
Problemas resolvemos na hora!
Milagres demoram mais um pouco...
Provérbio dinamarquês

Atividades 3:

Polinômio de grau \(n:\)
\(P(x)=a_n x^n+a_{n-1} x^{n-1}+a_1 x+a_0\)
  1. No arquivo N01.py, define os polinômios:
    1. \(P_1(x)=x-1\)
    2. \(P_2(x)=x^2-2x-1\)
    3. \(P_3(x)=x^3+x^2-x-2\)
    4. \(P_4(x)=x^4+3x^3-2x^2+x-4.0\)
    5. \(P_5(x)=x^5-2x^4+x^3+2x-4.0\)
    Python Listing: N01.py.
    P1=[-1.0,1.0]
    P2=[-1.0,-2.0,1.0]
    
  2. Calcule os valores em \(x=-5,-4,...,4,5.\) Arquivo N02.py.
    Python Listing: N02.py.
    from Polynomial import *
    from N01 import *
    
    
    xs=[-5.0,-4.0,-3.0,-2.0,-1.0,0.0,1.0,12.0,3.0,4.0,5.0]
    
    Ps=[P1,P2]
    
    for i in range( len(Ps) ):
        P=Ps[i]
        for x in xs:
            print x,Polynomia_Calc_Dumb(P,x),Polynomia_Calc(P,x)
    
  3. Calcule as somas: \(P_i(x) + P_j(x), \quad i,j \in [1,...,5]\) e seus valores para \(x=-5,-4,...,4,5.\)
    Arquivo N03.py.
    Python Listing: N03.py.
    from Polynomial import *
    from N01 import *
    
    
    xs=[-5.0,-4.0,-3.0,-2.0,-1.0,0.0,1.0,12.0,3.0,4.0,5.0]
    
    Ps=[P1,P2]
    
    for i in range( len(Ps) ):
        P=Ps[i]
    
        for j in range( i,len(Ps) ):
            Q=Ps[j]
    
            R=Polynomias_Add(P,Q)
            for x in xs:
                print i,j,x,Polynomia_Calc(P,x)+Polynomia_Calc(Q,x),Polynomia_Calc(R,x)
    
    0 0 -5.0 -12.0 -12.0
    0 0 -4.0 -10.0 -10.0
    0 0 -3.0 -8.0 -8.0
    0 0 -2.0 -6.0 -6.0
    0 0 -1.0 -4.0 -4.0
    0 0 0.0 -2.0 -2.0
    0 0 1.0 0.0 0.0
    0 0 12.0 22.0 22.0
    0 0 3.0 4.0 4.0
    0 0 4.0 6.0 6.0
    0 0 5.0 8.0 8.0
    0 1 -5.0 28.0 28.0
    0 1 -4.0 18.0 18.0
    0 1 -3.0 10.0 10.0
    0 1 -2.0 4.0 4.0
    0 1 -1.0 0.0 0.0
    0 1 0.0 -2.0 -2.0
    0 1 1.0 -2.0 -2.0
    0 1 12.0 130.0 130.0
    0 1 3.0 4.0 4.0
    0 1 4.0 10.0 10.0
    0 1 5.0 18.0 18.0
    1 1 -5.0 68.0 68.0
    1 1 -4.0 46.0 46.0
    1 1 -3.0 28.0 28.0
    1 1 -2.0 14.0 14.0
    1 1 -1.0 4.0 4.0
    1 1 0.0 -2.0 -2.0
    1 1 1.0 -4.0 -4.0
    1 1 12.0 238.0 238.0
    1 1 3.0 4.0 4.0
    1 1 4.0 14.0 14.0
    1 1 5.0 28.0 28.0
    
    
    Output from: /usr/bin/python N03.py
  4. Calcule os produtos: \(P_i(x) \cdot P_j(x), \quad i,j \in [1,...,5]\) e seus valores para \(x=-5,-4,...,4,5.\)
    Arquivo N04.py.
Messages:
0 secs.