% VARIANT 1: simple plot

%{
clc
clear all
x = 0:.01:2;
y = x.^2 - 2*x + 1;
plot(x, y)
%}

% VARIANT 2: same plot with labels and a differnt color and style

%{
clc
clear all
x = linspace(0, 2, 1000);
y = x.^2 - 2*x + 1;
plot(x, y, "r--") % draw in red with a dashed line
xlabel('x')
ylabel('y')
title("Graph of x^2 - 2x + 1")
%}

%{ 
    VARIANT 3: draw in one figure y = sin(x) and the previous parabola
    in another figure
%}

%{
clc
clear all
close all  % close all the previous figures
x = 0:0.01:2;
y = sin(x)
figure
plot(x, y)
figure
y = x.^2 - 2*x + 1;
plot(x, y)
%}

%{
    VARIANT 4: plot in the same figure the functions
    y = x^2
    y = sqrt(x^2 - 1)
    in the interval [-2 2]
%}
%{
clc
clear all
close all
x = linspace(-2, 2, 1000);
y = x.^2;
plot(x, y)
hold on
y = sqrt(x.^2 - 1);
plot(x, y)
%}

%{
    VARIANT 5: or
%}
%{
clc
clear all
close all
x = linspace(-2, 2, 1000);
y1 = x.^2;
y2 = sqrt(x.^2 - 1);
plot(x, y1, x, y2)
grid on
%}

%{
    VARIANT 5: or
%}
%{
close all
clear all, clc
f = @(x) x.^2;
fplot(f, [-2 2], 'm') % color magenta
hold on
fplot(@(x) sqrt(x.^2 - 1), [-2 2], 'c') % color cyan
%}

%{
    VARIANT 6: subplot with the following functions:
    1) y = cos(x)
    2) y = x*sin(x)
    3) y = x.^2 - 2*x + 1;
    4) y = x*tan(x)
in the interval [-4 4]
%}
%{
clc, clear all, close all
subplot(2, 2, 1)
x = -4:.1:4;
y = cos(x);
plot(x, y)
subplot(2, 2, 2)
x = linspace(-4, 4, 100);
y = x.*sin(x);
plot(x, y)
subplot(2, 2, 3)
y = x.^2 - 2*x + 1;
subplot(2, 2, 4)
fplot(@(x) x.*tan(x), [-4 4])
%}

%{
VARIANT 7: z = sin(x) cos(y)
%}
%{
clc, clear all, close all
X = 0:0.1:4;
Y = -2:0.1:1;
[x, y] = meshgrid(X, Y);
z = sin(x).*cos(y);
mesh(x, y, z)
xlabel('x')
ylabel('y')
zlabel('z')
% or
figure
surf(x, y, z)
xlabel('x')
ylabel('y')
zlabel('z')
% or use anonymous functions
f = @(x, y) sin(x).*cos(y);
figure
fsurf(f, [0 4 -2 1])
xlabel('x')
ylabel('y')
zlabel('z')
%}

%{
VARIANT 8: z = sqrt(x) cos(y)
%}
clc, clear all, close all
%X = -2:0.1:4; % it doe not work here
%Y = -2:0.1:1;
%[x, y] = meshgrid(X, Y);
%z = sqrt(x).*cos(y);
%mesh(x, y, z)
%xlabel('x')
%ylabel('y')
%zlabel('z')
% or
%figure
%surf(x, y, z)
%xlabel('x')
%ylabel('y')
%zlabel('z')
% or use anonymous functions
f = @(x, y) sqrt(x).*cos(y);
figure
fsurf(f, [-2 4 -2 1])
xlabel('x')
ylabel('y')
zlabel('z')