[Tutor] exercise problem
rwobben at hotmail.com
Fri Aug 27 19:56:35 CEST 2010
Now I have this :
def add_vectors(u, v):
>>> add_vectors([1, 0], [1, 1])
>>> add_vectors([1, 2], [1, 4])
>>> add_vectors([1, 2, 1], [1, 4, 3])
[2, 6, 4]
>>> add_vectors([11, 0, -4, 5], [2, -4, 17, 0])
[13, -4, 13, 5]
while teller < len(u):
getal1 = u[teller] + v[teller]
vector= [1, 2, 1], [1, 4, 3]
uitkomst = add_vectors(u,v)
The only problem I have is to build up uitkomst2.
on every loop getal1 has the value of the outcome.
So I thought this would work
uitkomst2 [teller] = getal1
But then i get a out of range.
Date: Fri, 27 Aug 2010 10:19:30 -0700
From: alan.gauld at btinternet.com
Subject: Re: [Tutor] exercise problem
To: rwobben at hotmail.com
>u v, result
u : [1.0] v: [1,1] result [2.1]
OK, Great, you got that.
first split u en v in only numbers.
No, you should leave them as lists.
Then add u en v and u and v
put the outcome in the new vector.
Almost except you don't know how many elements there will be so
you need a loop to process all the elements.
outcome= [outcome u, outcome[u]
This confused me, the output should be:
[ u+v, u+v, u+v, ...., [u[n]+v[n] ]
And in case you are wondering, a vector is used in math to,
for example, represent a point in space. A 2 dimensional
point has an X,Y coordinate so we can create a 2 element
We can add, subtract and multiply vectors. Vectors can also
be used to represent other physical measures, for example
AC electric current has a magnitude and phase angle at any
point in time. These two values can be combined as a vector.
We can use bigger vectors to represent, for example the
set of inputs to a parallel port printer, so we would have a
list of 8 binary values. Once again we can express mathematically
the processing of this vector as a function and by applying the
function to the vector deermine the expected output for any given input.
That could be, for example, an ASCII character for the printer example...
They are very important in science and engineering.
The tutorial you are following does expect the reader to be quite
math literate - it is part of a university comp sci course after all. If
you do not have a strong math background you may find some of
the others more readable. For example mine( :-) ) does not assume
any knowledge of math beyond basic high school level - really basic
geometry and arithmetic.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor