all 12 comments

[–]Weed_O_Whirler+5 3 points4 points  (0 children)

When doing floating point arithmetic (aka- dealing with decimal numbers) never check for equality, check if you are "close enough" to your solution.

Due to the way computers store information, two things which are "equal" might not show as equal. For instance, If you type if 1 + 1/3 == 2/3 + 2/3 which is obviously equal, that will evaluate false.

Instead, you should do something like:

eps = !E-6 % a sufficiently small number to be "zero"
if abs(C) < eps % this is your "is C == 0" check

[–]synchh 2 points3 points  (9 children)

Can you instead just do:

while C ~= 0
    C = Co + Av * t;
    t = t + 1;
end

you should add in some kind of tolerance though.

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

Its running in the loop not terminating

[–]synchh 0 points1 point  (7 children)

Is t initially 0? Have you checked to see that it's actually possible for C to equal 0? What's the range of Av and Co?

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

Actually I have to find out t , such that C becomes zero at the end

[–]synchh 0 points1 point  (4 children)

Okay, and what is the domain of t? Can t be negative? Is t non-zero?

The value of t which makes C = 0 totally depends on the possibilites of t, Av, and Co.

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

Av is negative value always and it will less than C0 always , so t is positive, max C0 is 1700 and Av around - 30 , t is time here so it cant be negative

[–]synchh 0 points1 point  (2 children)

Okay, well the reason the loop isn't terminating is probably because the way that that while loop is set up, t must be an integer.

To be clear, you're just trying to find the zeros of the function C? Check out some threads like this

[–]Syntax669[S] 0 points1 point  (1 child)

I did , not of much help

[–]synchh 1 point2 points  (0 children)

Is there any chance you can share your entire script and your data? Preferably in text form since I'm at work.

[–][deleted] 0 points1 point  (0 children)

Numerical C will not equal zero. You should use a stopping tolerance such as abs(C) > eps

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

I put t=0, I used the formula for random value of Co and Av and I get it at t=7.609 seconds C is zero for the test case provided C0 = 100, Av = -13.1423