% Matlab script curvature.m
% Calculates curvature for GG303 fold lab

% Problem 1: Parabola
x = -1:0.01:1;
y = x.^2;

yp = 2*x;
ypp = 2;
k1 = abs(ypp)./ ((1+ yp.*yp).^(3/2));
figure(1)
subplot(2,1,1)
plot(x,y,x,y+0.1,x,y-0.1)
%axis([min(x) max(x) min(y) max(y)])
%axis equal
xlabel('x')
ylabel('y')
title('Parabolic Curve and Its Curvature')
subplot(2,1,2)
plot(x,k1)
xlabel('x')
ylabel('k')
title('Curvature of Parabolic Curve')

% Problem 2: Inverse cubic function
x = 0:0.01:1;
y = x.^(1/3);

yp = *********;
ypp = *********;
k2 = abs(ypp)./ ((1+ yp.*yp).^(3/2));
figure(2)
subplot(2,1,1)
k2(1) = 0;
x = [-fliplr(x) x];
y = [-fliplr(y) y];
k2 = [fliplr(k2) k2];
plot(x,y,x,y+0.1,x,y-0.1)
xlabel('x')
ylabel('y')
title('Inverse Cubic Function')
subplot(2,1,2)
plot(x,k2)
xlabel('x')
ylabel('k')
title('Curvature of Inverse Cubic Function')

% Problem 3: Sine wave
x = -pi:0.01:pi;
y = sin(x);

yp = *********;
ypp = *********;
k3 = abs(ypp)./ ((1+ yp.*yp).^(3/2));
figure(3)

subplot(2,1,1)
plot(x,y,x,y+0.1,x,y-0.1)
xlabel('x')
ylabel('y')
title('Sinusoidal Function')
subplot(2,1,2)
plot(x,k3)
xlabel('x')
ylabel('k')
title('Curvature of Sinusoidal Function')


% Problem 4: Arc tangent function
x = -2:0.01:2;
y = atan(x);

yp = *********;
ypp = *********;
k4 = abs(ypp)./ ((1+ yp.*yp).^(3/2));
figure(4)

subplot(2,1,1)
plot(x,y,x,y+0.1,x,y-0.1)
xlabel('x')
ylabel('y')
title('Arc tangent Function')
subplot(2,1,2)
plot(x,k4)
xlabel('x')
ylabel('k')
title('Curvature of Arc tangent Function')


% Problem 5: Beam Function
x = -1:0.01:1;
y = x.^4 - 2*x.^2 + 1;

yp = *********;
ypp = *********;
k5 = abs(ypp)./ ((1+ yp.*yp).^(3/2));
figure(5)

subplot(2,1,1)
plot(x,y,x,y+0.1,x,y-0.1)
xlabel('x')
ylabel('y')
title('Beam Function')
subplot(2,1,2)
plot(x,k5)
xlabel('x')
ylabel('k')
title('Curvature of Beam Function')
