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

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:

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.