Accuracy in float and double (in C)
From: Steve (carvegio_at_gmail.com)
Date: 02/25/05
- Next message: skearney_at_accessbee.com: "Can numerical analysis be applied to a keyboard?"
- Previous message: Pierre Asselin: "Re: orthogonalizing vectors"
- Next in thread: Peter Spellucci: "Re: Accuracy in float and double (in C)"
- Reply: Peter Spellucci: "Re: Accuracy in float and double (in C)"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 25 Feb 2005 01:19:34 +0000 (UTC)
Hello, I am trying to solve this problem in c and I am having a great
deal of problem trying to figure out what is going on.
I was hoping someone could please explain it to me.
It involves a three term recurrence x[i]=A*x[i-1]+B*x[i-2]
with x[0]=x[1]=...x[n]=1/3 (0.33333r).
A is (double)(100001+1), B is (double)(-100001)
When I work this out using float I get perfectly accurate answers
but when I change type to double, my answers are horribly wrong
and get worse and worse as we progress, and similarily with long
double.
I don't understand why, I know floating point can not represent
1/3 accurately. But I would of thought that float would have the
same problem storing it as float, and cause bad results.
But this is not the case.
Also if we change the recurrence to
x[i]=(A-1)*x[i-1]+B*x[i-2]+x[i-1] we get perfect answers, and I
dont understand how this is so different to what we had before,
just taking one part of A outside.
Hope someone can help
Thanks
- Next message: skearney_at_accessbee.com: "Can numerical analysis be applied to a keyboard?"
- Previous message: Pierre Asselin: "Re: orthogonalizing vectors"
- Next in thread: Peter Spellucci: "Re: Accuracy in float and double (in C)"
- Reply: Peter Spellucci: "Re: Accuracy in float and double (in C)"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|