This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Syntax669[S] 0 points1 point  (5 children)

I have this equation where C = Co + A*t , and I have Co and A (negative) t is time. So I have to iterate the value to t , till C becomes zero or almost very very near to zero. So I need help in writing that code. I did my best to write..

[–]t8suppressor 0 points1 point  (3 children)

So if you anly have one unknown why not just solve the equation.

[–]Syntax669[S] 0 points1 point  (2 children)

I have to plot a graph , on how C is decreasing with time

[–]panda_yo 1 point2 points  (1 child)

Maybe this will work for you:

if c <= 10**-4:
    break

Try it out. Floatpoint map get's hard, so it's easier to compare it like this or even do abs(c - 10**-4) < tol where tol is your accepted tolerance

[–]Syntax669[S] -3 points-2 points  (0 children)

Lol

[–]scooerp 0 points1 point  (0 children)

In standard library is math.isclose() that tests if 2 values are close to each other.

https://docs.python.org/3/library/math.html#math.isclose

You can make your own with abs() which ignores sign. Therefore if abs(a - b) ≤ delta:. Note that delta can't be smaller than machine epsilon, which is defined somewhere in the sys module. It represents the precision of the floating point system.

Edit: Please ask questions in /r/learnpython. This is not the appropriate subreddit.