|
"mlt" <asdf@asd.com> wrote in message <49467e39$0$90269$14726298@news.sunsite.dk>...
> I have made this in matlab:
>
> x=0:9*pi/2;
>
> % Using matlab's gradient
> f = sin(x);
> FX = gradient(f);
>
> % Using the definition that df/dx for sin(x) is cos(x)
> fderv = cos(x);
>
> But when I print them I get:
>
> FX =
> 0.8415 0.4546 -0.3502 -0.8330 -0.5500 0.2387 0.8080
> 0.6344 -0.1224 -0.7667 -0.7061 0.0037 0.7101 0.7636 0.5704
>
> fderv =
> 0.5000 0.2702 -0.2081 -0.4950 -0.3268 0.1418 0.4801
> 0.3770 -0.0728 -0.4556 -0.4195 0.0022 0.4219 0.4537 0.0684
>
> Why are the result different?
The gradient function attempts to approximate the derivative using discretely spaced points, but your points are so far apart this approximation must necessarily be a very poor one.
By the way, the values you give to fderv don't agree with the x you defined. For example acos(0) is 1, not 0.5. What is the actual x you used?
Roger Stafford
|