% User input

a=0; b=5; c=0.5;

% a,b define an interval and
% c is a point inside it.

% the line below defines a
% vectorized function f(x) of
% a symbolic variable x.
% We may enter any formula.
% You can experiment with different values for
% a,b, and c and different functions.

f=@(x)sin(exp (sin (3*x))).*cos (x);

% End of user input.

% Next, we compute the symbolic
% derivative of f(x).

syms x
df=diff(f(x),x);

% dfan is the anonymous function
% that computes the value of the derivative.

dfan=@(x)subs(df);

% Here we evaluate the slope of the line tangent to
% the graph of y=f (x) at the point (c,f (c).

m=dfan(c);

% Now plot the graph of y=f (x) using 200 points.
% I chose 200 because with 50 points the was
% very ragged.

X=linspace(a,b,200);
clf
plot(X,f(X))
hold on

% Finally we plot a piece of
% the tangent line in red.

Z=linspace(c-1,c+1,10);
Y=f (c)+m*(Z-c);
plot (Z,Y,'r')

% A nice thing to try is running this file with different values of c
% to get lines tangent to the graph of y=f(x) at different points.