Function handling with derivative of sin
Show older comments
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
Stephen23
on 20 Aug 2018
@Shivam kumar: please show us the complete error message. This means all of the red text.
Answers (2)
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
Walter Roberson
on 19 Aug 2018
f = @(x) sin(x)
is just a version of
f = @sin
with more overhead and otherwise the same effect.
Shivam kumar
on 19 Aug 2018
Walter Roberson
on 19 Aug 2018
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
Find more on Testing Frameworks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!