Filter löschen
Filter löschen

Taking derivatives with fft?

5 Ansichten (letzte 30 Tage)
qwerty ed
qwerty ed am 12 Apr. 2015
Bearbeitet: pfb am 12 Apr. 2015
Hi everyone,
(Please note my entire code is not defined here, this is just the gist of my problem)
Say that I have an initial shape (defined in one file):
M = 32;
h = (2*pi)/M;
a = 0:h:((2*pi)-h); a = a';
x1_0 = (4+cos(3*a)).*cos(a); % These two correspond to x_1 and x_2 in the next file
x2_0 = (4+cos(3*a)).*sin(a);
and code to take the derivative of that shape defined (in another file):
x_1 = x1;
x_2 = x2;
x_1a = deriv(x_1);
x_1aa = deriv(x_1a);
x_2a = deriv(x_2);
x_2aa = deriv(x_2a);
and a function for calculating the derivatives defined (in another file):
function df=deriv(f)
Except I'm not sure how to write this function which calculates the derivatives which takes in and returns a vector. I've tried doing this with fft and finite difference methods, but am still not getting correct output. ONLY THESE TWO METHODS OF COMPUTATION ARE ACCEPTABLE. Any help writing this correctly would be appreciated. Thank you.
  2 Kommentare
Geoff Hayes
Geoff Hayes am 12 Apr. 2015
qwerty - is this homework? Why are only these two methods of computation acceptable?
pfb
pfb am 12 Apr. 2015
Bearbeitet: pfb am 12 Apr. 2015
So, your "x vectors" are actually samples of some functions, and you want to the derivatives of those functions.
To do that, you need to use the information about the independent variable, or at least its increment between two subsequent samples of the function, if that's constant. This applies both with diff or with fft (actually, with fft it must be constant).
It seems to me that your deriv function only knows about the values of the function at the sampling points, but not which points are those.
The first derivative is easy. The second derivative might be trickier.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by