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

Vectores no Plano
Whom takes fun only as fun.
And serious only seriously.
Misunderstood both.
Piet Hein
< Com Escalar | Multiply | Com Vetor >

Multiplicar Vetor com Escalar ou Vetor?

  • Vetor com vetor: Escalar!
    [; \underline{u} \cdot \underline{v} = |\underline{u}| |\underline{v}| \cos{\theta} = \sum_1^i u_i v_i \in \mathbb{R} ;]
  • Vetor com escalar: Vetor!
    [; \underline{u} ~c = \sum_1^i u_i c \in \mathbb{R}^n ;]
Python Listing: ../../Code/Vector.py.
    def __mul__(v,arg2):
        
        if (arg2.__class__.__name__=="Vector"):
            return v.__mul_Vector__(arg2)

        #Second argument should be e scalar from now on.
        
        #Make sure it is float
        if (arg2.__class__.__name__=="int"):
            arg2*=1.0
            
        if (arg2.__class__.__name__=="float"):
            return v.__mul_Scalar__(arg2)

        print "Vector.__mul__: Invalid second argument: ",arg2.__class__.__name__

    def __imul__(v,w):
        #Unary multiplication: u=*v
        return v*w

< Com Escalar | Multiply | Com Vetor >
Messages:
0 secs.