MATLAB Answers

Derivative of a function in a particular point

2 views (last 30 days)
Hi
I have an external function y= function fa(x)
y=sin(x./pi)
end
i want in the main program to find the derivative of fa in numerical point
thank you
George

Accepted Answer

george veropoulos
george veropoulos on 16 Jul 2021
format long
x = 2 ;
h = sqrt(eps) ;
f1=(sin(x + h)./(x+h) - sin(x)./x) / h % -0.400000
% -0.435397773981094
f2=cos(x)./x-sin(x)./x^2
% -0.435397774979992
  2 Comments

Sign in to comment.

More Answers (1)

Jan
Jan on 16 Jul 2021
Use one of the quotients of differences to get a numerical approximation of the derivative:
x = 1.2345;
h = sqrt(eps);
dy_right = (fa(x + h) - fa(x)) / (h)
dy_left = (fa(x) - fa(x - h)) / (h)
dy_both = (fa(x + h) - fa(x - h)) / (2 * h)
function y = fa(x)
y = sin(x./pi)
end
  9 Comments
george veropoulos
george veropoulos on 19 Jul 2021
thank you all! very helpfull dicussion
George

Sign in to comment.

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!