Monday, October 31, 2011

Programming - Exercise 5

Today, we introduced the programming.

For people who have taken 4A with mason, will need to go to the handout #2 of the programming, which is a more advance handout than the other handout.

Since I had 'some' programming experience with mouse trap car, and the space mission to Mars, I had to do the handout #2. Also, I am taking a introduction of C language, which helps me a lot in this package since I learn most of the material in my class already. At the end of the handout, we were suppose to answer the question at the end of exercise 5, which is the create two array, one is sin(2*pi*i/100) the other is cos(s*pi*i/100) where i is a constant from 1 to 100
After created the two arrays, we want to find the dot product of the two arrays, which suppose to be zero since the dot product of a sine and cosine function is zeor

Here is the program I have


from numpy import*
from decimal import*
xx=zeros(100,int)
yy=zeros(100,int)
zz=zeros(100,int)
result=0
for i in range (0,99):
    xx[i]=sin(2*pi*i/100)
    yy[i]=cos(2*pi*i/100)
print xx
print yy
for i in range(0,99):
    zz[i]=xx[i]*yy[i]
    result=result+zz[i]
print result

The first line is to input the mathematical calculation of sin and cos from the library

Later, I declared two arrays of xx and yy to put the calculated varaibe into the two arrays with a loop to input the number into each cell

At the end I declared another array of zz to do the dot product of the two arrays and the result is zero as we expected

No comments:

Post a Comment