Advertisement

header ads

Learn the Vectors Let Python Do work



One of the key issues that are taught at the beginning of introductory physics are the idea vectors. Students really need knowledge with them, if we want to use force and speed.

Just covers about all courses, of course, but I will do it a little differently. I will use Python to help students perfect their skills vector. But first, a quick introduction to this.


What is a vector?

Here is a definition that I am not a fan of:

Vector: A quantity that has both magnitude and direction. Example: speed, power, acceleration. A quantity that only has the magnitude would be a scalar.

It is not bad, but I do not like to point out direction. It suggests that one can express a vector with just a number and an angle. (Yes, I know he does not say, but that's what some students are reading.) Ok, here's my definition, which I admit is not perfect:

Vector: A set that contains more than one bit of information. Three-dimensional vectors have three components. Example: speed, power, acceleration. A vector with a single piece of information (a 1D vector) is a scalar.

But how do you use a vector? I will not go into more detail, because I have done it before. How about the highlights?

  • One way to represent a vector is to list its x, y, and z. Something that v = <1,2,3> m / s. Of course, there are many ways to represent a vector.
  • There is one thing called vector addition. If A and B are vectors, A + B = C, where C is also a vector. The components of vector C is the sum of components A and B. (People differ from the typical variables of scalar vector by drawing an arrow above it, but it's not easy to do when you write so I used in bold .)
  • Multiplication Scalar is a vector when multiplied by a scalar. To find the result, multiply each vector component of the scale value.
  • The size of a vector is the square root of the sum of the squares of the components. Yes, it is terrible to write, but I will just try to pass.
  • A unit vector is a vector of one magnitude and no units-good, which seems strange. The main idea is a unit vector describing the direction of a vector. Believe me, it's okay.
  • OK, that's pretty vectors. Honestly, I do not want to go over all the little details. Instead, I want to show you how to use Python to help students understand the vectors.

Vectorial operations with Python

Before continuing, I will assume that you have a basic understanding of vectors. If you do not, it's cold, but there may be points where you can refer to previous documents from ... somewhere. Not here.

In case you are not familiar with Python, I will use with the visual module (called VPython). The visual module provides a lot of cool things, but most importantly it contains a class variable of vectors. But adding scalars? Let's go over it. In this case, I will use a web-based implementations of VPython, trinket.io, because I can embed it on the page and you can change the code as much as you want.

Here is a small piece of code that shows more scalar and scalar multiplication (between two scalars). Click the "play" button to run the code and "pen" to edit it.





If you have not played it with Python before you really need to change anything in the code. It will not break, I promise. In fact, one realizes that this would make a great calculator for your physical homework. Yes it is true.

Now, for a similar calculation with vectors.



Note that by assigning a variable to a vector, VPython will treat it as a vector. Here is a quick test attempts to multiply the A vector and the B vector. Yes, just change the code above. You should get a result that includes NaN. This is Python's way of saying "this is not a number, and you can not do it." I must point out that Python is the sensitive case- "a" is not the same as "A"

How about a smaller demo add vectors. Look at this code (and run):



You can see that when a variable is created as a vector, the components of that vector are reached by adding a ".x" or ".Y" to the end of the name. You should be able to change the code to show that the c vector is really the same as A + B. Then we will calculate the size of a vector. I will do it in two ways in the code below.



In the first method, I calculate the size of the vector by the quadrature of each component, and then add them before taking the square root (which is the definition of magnitude). Note that "sqrt ()" is a built-in function of the square root, and you can raise a scalar to a power with "**" notation. The second method is a little easier, it uses the integrated function "gastrointestinal ()". If you insert a vector, returns the size. Go ahead and add this line to the code above and run it:

Print ("size" mag (vector (1,2,3)))

Does it work? Yes, but always check.

What if the unit vectors? Here is another piece of code that calculates the unit vector in two ways.



Again, you can see that there are two ways to find a unit vector: the long way and the built-in way using the "standard ()" tool.

Visualization of vectors

VPython can also drag vectors. Here is a code that shows two vectors:



The "arrow" is another embedded object in VPython. There are really only three major features of the arrow of the object:

Pos: This is the mode for the beginning of the arrow to think about what the site of the vector.
Axis: This is a vector from the beginning of the vector to the end so that the real vector.
Color: I hope it is obvious that this is the color of the arrow.
Try adding this line of code:

Barr.pos = Aarr.pos + Aarr.axis

You must ensure that now vector B (yellow) begins at the end of vector A. You have just moved the starting position B. Here are some other things to try.

Create an arrow-you third vector can call it Carr.
Make Carr equal to A plus B and display it so that it is clear these add up.
Assume that vectors A and B are position vectors. Create vector C so that C = B - A and can represent the movement from A to B. Make sure it displays correctly

Source:-WIERD

Post a Comment

0 Comments