clear all; close all

% Use Symbolic Variable
syms x; 

% Declare f(x)
f = x^2;

% Differentiate f(x)
df = diff(f);

% Gradiant at (x0,y0)
x0 = 2; y0= 4;

m_tan = subs(df,x0)
m_norm = - 1/m_tan

%compute c_tan and c_norm (y-axis Intercepts)
c_tan = y0 - m_tan*x0;

c_norm = y0 - m_norm*x0;


%Declare 
tan_eqn = m_tan*x + c_tan

normal_eqn = m_norm*x + c_norm


%Plot f(x), tangent and normal at (x0,y0)

ezplot(tan_eqn,[-5 5]);

hold on;

gh1 = ezplot(normal_eqn,[-5 5]);

set(gh1,'Color','red');

ezplot(f,[-5 5]);

plot(x0,y0,'o','LineWidth',2,'MarkerEdgeColor','k','MarkerFaceColor','r','MarkerSize',10);

axis equal;
shg