Function handling with derivative of sin

Testing a script to find derivative of f=@sin but Error is coming up every time,I tried to fix it but all efforts got drained .Anyone throw some light
Function itself:
function [finitederivative] = finiteDerivativeApprox(f(x),x)
%Test if function value is able to calculate
%derivative of given assigned values
%f-a handle to function to test
%x-values (scalar or array) to evaluate f at
[finitederivative] = (f(x+h) -f(x) )/h;
end
*Test script file*
clear
clc
f=@sin;
x=pi/3;
h=1e-6;
approxDeriv=finiteDerivativeApprox(f,x,);
fprintf('%.4f\n',approxDeriv);

1 Comment

@Shivam kumar: please show us the complete error message. This means all of the red text.

Sign in to comment.

Answers (2)

madhan ravi
madhan ravi on 18 Aug 2018
Edited: madhan ravi on 18 Aug 2018
What happens if you try the below code?
f = @(x) sin(x)
x=pi/3
f(x)
Note: Function Handle should be defined inside parentheses

2 Comments

f = @(x) sin(x)
is just a version of
f = @sin
with more overhead and otherwise the same effect.
Yes I have tried using @(x)sin(x),still same problem

Sign in to comment.

function [finitederivative] = finiteDerivativeApprox(f, x, h)
%Test if function value is able to calculate
%derivative of given assigned values
%f-a handle to function to test
%x-values (scalar or array) to evaluate f at
[finitederivative] = (f(x+h) -f(x) )/h;
end
together with
f = @sin;
x = pi/3;
h = 1e-6;
approxDeriv = finiteDerivativeApprox(f, x, h);
fprintf('%.4f\n', approxDeriv);

Categories

Asked:

on 18 Aug 2018

Commented:

on 20 Aug 2018

Community Treasure Hunt

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

Start Hunting!