Domanda

I was wondering if someone could help me figure out how to generate a new tuple with a previously generated tuple. What I have so far is just generating an empty tuple

import math as m
grav = 9.807 #[m/s**2] gravity http://physics.nist.gov/cgi-bin/cuu/Value?gn value obtained from NIST
H = 1.100 #[m] Height of the posts/supports
rho = 2.000 #[kg/m] density of the chain
DIS = 0.980 # distance of supports from x = 0
SEG = 10000. #number of divisions
SEGL = 2*DIS/SEG # size of segments
aa = 0.6 #[m]

#xtuple
n=0
xterms = []
xterm = -DIS
while n<=SEG:
    xterms.append(xterm)
    n+=1
    xterm = -DIS + n*SEGL
#ytuple
yterms = []
yterm = H
while n<= SEG:
    yterms.append(yterm)
    n+=1
    yterm = H + aa*m.cosh(xterms[n]/aa) -aa*m.cosh(DIS/aa)
print yterms

What I eventually have to do is solve for the length with sqrt((xi - x(i-1))^2 + (yi - y(i-1))^2). Then angles, net force and aa will have to vary from .6 to 3.9.

I can't use fancy functions as this is an intro course. I have to use such things as (xterms[n] -xterms[n-1])**2

È stato utile?

Soluzione 3

Thanks for the help, but I managed to figure out my silly mistake. This is the proper way to do it. I wrote out the process, by hand and it allowed me to come to this solution.

k=0
yterms = []
while k<=SEG:
    yterm = H + aa*m.cosh(xterms[k]/aa) -aa*m.cosh(DIS/aa)
    yterms.append(yterm)
    k+=1
print yterms

Sorry to waste your time

Altri suggerimenti

Your yterms is empty because n is still 10001 from the first loop.

The second while loop isn't executed because n is already greater than SEG.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top