## Norming a Vector

This is the place for queries that don't fit in any of the other categories.

### Norming a Vector

Hi,

Code: Select all
`import mathdef length_squared(u):    return sum([a ** 2 for a in u])def length(u):    return math.sqrt(length_squared(u))    def scale_by_scalar(u, scalar):    return [a * scalar for a in u]def norm(u):    return scale_by_scalar(u, 1 / length(u))print norm([100, 6])`

The answer of this program is: [0.9982048454657786, 0.05989229072794672]

However, if I were to set the print norm function as the following: print norm([100, 0]) it would give me: [1.0, 0.0]

Why does it give me those floating point values if 100 * (1 / sqrt(100^2)) is 1 and 6 * (1 / sqrt(6^2)) is 1? I also thought sum adds up these two values which would give 2?
Indiiyana

Posts: 10
Joined: Tue Nov 26, 2013 1:55 am

### Re: Norming a Vector

Code: Select all
`[100 / sqrt(100**2 + 6**2), 6 / sqrt(100**2 + 6**2)]`
Code: Select all
`100 * (1 / sqrt(100**2)) + 6 * (1 / sqrt(6**2))`
Friendship is magic!

R.I.P. Tracy M. You will be missed.

stranac

Posts: 1790
Joined: Thu Feb 07, 2013 3:42 pm

### Re: Norming a Vector

I see.

My logic is completely wrong then, I don't suppose you could tell me what happens step by step with this program?

Thanks.
Indiiyana

Posts: 10
Joined: Tue Nov 26, 2013 1:55 am