E46Fanatics

E46Fanatics (http://forum.e46fanatics.com/index.php)
-   General Off-Topic (http://forum.e46fanatics.com/forumdisplay.php?f=24)
-   -   CS Guys - Help me out really quick (http://forum.e46fanatics.com/showthread.php?t=965818)

cowmoo32 01-15-2013 04:39 PM

CS Guys - Help me out really quick
 
This is some python code but I fugure the loop logic should be the same in all languages. I'm using this function to plot decay:

100e-t/5

And I need it to step through 1 second intervals 0-->5 and plot the result. I'm sending the results to a 1D array. The array and plotting are working fine but for some reason it's not calculating correctly.

Code:

for j in range(6):
        num2[j] = n2
        n2 = 100*e**(-j/5)

And this is the array that it spits out. I have no clue why it repeats 100 and then jumps down to 36.
Code:

[ 100.          100.          36.78794412  36.78794412  36.78794412    36.78794412]

Treburkulosis 01-15-2013 04:41 PM

about 350

kuksul08 01-15-2013 04:43 PM

Terrorists win.

NOVAbimmer 01-15-2013 04:48 PM

42

bioman 01-15-2013 05:16 PM

Is n2's initial value 100? When you calculate n2 for the first loop, you're basically doing 100*1.

cowmoo32 01-15-2013 06:00 PM

Quote:

Originally Posted by bioman (Post 15064375)
Is n2's initial value 100? When you calculate n2 for the first loop, you're basically doing 100*1.

Yeah. And that's correct, at t=0, n2=100. But at t=1, it should be 81.87

edit: Messing with j just shifts the array but still gives the wrong answers. I know it's a simple fix but for whatever reason I'm not seeing it

http://i.imgur.com/1dWOr.png
http://i.imgur.com/4seNZ.png

cowmoo32 01-15-2013 07:09 PM

Ok so something is wrong with the math, not sure why it's doing this
http://i.imgur.com/4hVDx.png

dreamdrivedrift 01-15-2013 08:59 PM

didn't really look closely but it looks like you inputted the array value before you actually calculated n2

nikkeiS2K 01-15-2013 09:19 PM

Try using parenthesis.
Does the exp() function work the same way as e**?
I see you have it two different ways.

mistrzmiasta 01-15-2013 09:23 PM

just use science.

bimmerfan08 01-15-2013 09:28 PM

You're a civil engineer :p

cowmoo32 01-15-2013 09:41 PM

I need to set everything in the exp(), or e**, function as a floating point instead of an integer. That was the problem

cowmoo32 01-28-2013 05:36 PM

I'm at a loss here. It keeps telling me I'm using invalid sytanx when delcaring density. I've tried changing the variable name, tried commenting out the else/elif statements even though they work fine, tried putting the equation to the right of it in parentheses, but it keeps telling me the same thing. All I want to do is test to be sure the equation is correct :banghead:


Code:

height = raw_input('Fall height (meters): ')
height = float(height)

t_0 = 288.15        # Air temperature (degrees kelvin) at sea level
L = 0.0065        # Temperature lapse rate (degrees kelvin / m)
R = 287.058
g = 9.80665
R2 = 8.31432
m = 0.0289644
p_0 = 101325
t_0 = 273.15
Lb = -0.0065
power = (g*m)/(R2*Lb)
temp = 271

if (0.0<=height<100):
        temp = 100

elif (100<=height<200):
        temp = 200

elif (200<=height<300):
        temp = 300

elif (300<=height):
        temp = 400


pressure = p_0*(t_0/(t_0-Lb*(height))**power
density = pressure/(R*temp)

print(temp)
print(pressure)
print(density)


VaderDave 01-28-2013 05:39 PM

I'm not sure what any of this has to do with customer service. :dunno:

Spiral Prophet 01-28-2013 05:45 PM

The invalid syntax isn't with the density equation.. it's with the line previous.. you're missing a ) in the formula.. you have 3 ( and only 2 )

Python tends to report an invalid syntax at the line after the actual problem

cowmoo32 01-28-2013 05:48 PM

Quote:

Originally Posted by Spiral Prophet (Post 15104961)
The invalid syntax isn't with the density equation.. it's with the line previous.. you're missing a ) in the formula.. you have 3 ( and only 2 )

Python tends to report an invalid syntax at the line after the actual problem

:facepalm: This is why I will never code for a living. Small sh!t like this drives me nuts. Thanks.

Spiral Prophet 01-28-2013 05:56 PM

Quote:

Originally Posted by cowmoo32 (Post 15104975)
:facepalm: This is why I will never code for a living. Small sh!t like this drives me nuts. Thanks.

not a problem.
Just remember that debuggers are smart but also really dumb.. if it points to something as an error.. the chance of the error being the previous line is just as good as it being where it's pointing.

Coding all day is relaxing as hell..
however coding for micros is in itself a whole other level of hell.. That's what i do all day.

cowmoo32 01-28-2013 06:03 PM

It's too tedious for me, I need action. Although I'll admit that when everything works well it does feel good.

v8 5 01-28-2013 06:05 PM

Quote:

Originally Posted by kuksul08 (Post 15064254)
Terrorists win.

:rofl:

Grande D 01-28-2013 07:10 PM

I HATE Python. :impulss:


All times are GMT -5. The time now is 04:16 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
(c) 1999 - 2011 performanceIX Inc - privacy policy - terms of use