0

Hi I'm working on an iOS app that requires finding the z value of the accelerometer and then deriving it twice of find the "Jounce" value. Heres what I have so far:

In

-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration

I get the "z" value of acceleration and assign it to a variable:

float currentAccc = acceleration.z;

After this I don't know how to differentiate twice. How do I differentiate in Obj-C?

Thanks

virindh
  • 3,775
  • 3
  • 24
  • 49

1 Answers1

1

You'll want to know something about finite differences in order to do this.

A single discrete value is insufficient.

A first order derivative w.r.t. time would look like this:

da/dt(t) ~ (a(t+dt)-a(t))/dt
d^2a/dt^2(t) ~ (da/dt(t+dt)-da/dt(t))/dt

(I could make this easier to read if I had LaTeX.)

You can use other formulas, but these are simplest.

The ideas are commonly understood from differential calculus.

duffymo
  • 305,152
  • 44
  • 369
  • 561
  • I can obviously divide by time :) but thats where my problem arises, how do I get the exact time between UIAcceleration readings? – virindh Jan 17 '14 at 21:24
  • I don't think you understand calculus. That's not a time; it's a time *difference*. These formulas assume that the derivative is a constant over that small interval, so you're free to assume that the value holds at the start, end of the interval and every other time point in between. Calculus tells you that the derivative is the limit as the time difference approaches zero; you're approximating it with finite differences because that's what your computer can do. – duffymo Jan 17 '14 at 21:35
  • sorry thats what I meant! thats why asked about finding time Between UIAcceleration delegate messages. – virindh Jan 17 '14 at 21:37