%% write and call functions
% look at the function first 
% examplefunct
help examplefunct
% function y= examplefunct(x)
% y=2*x;
% end
% then i call the function by giving it a value examplefunct(...)
%% 
examplefunct(17)
% or a random value
examplefunct(rand)
% or the return value can be assign to another value
z=examplefunct(18)

%% with multiple input arguments
examplefuncttwo(17,6)


%% functions that return more than one value

[a1 a2] =examplefunctthree(5,6) 

%% choosing from more than just a few options. 
% The following function receives
% an integer which should be in the range
%from 0 to 10. The program then returns a corresponding result: pass or fail 

quiz = 8;
lettergrade = examplegrade(quiz)

%%
quiz = 7;
lettergrade = examplegrade(quiz)

%% function functions
% used to pass functions to other functions
% 
fnfnexamp1(@sin)


%% scatter plots
N=60;
x = linspace(0,100,N);
y=exp(-x/10).*x.^2;
scatter(x,y);

%% change the of markers
scatter(x,y,200);
%% specify the color
scatter(x,y,200,'r');
%% filling in the markers
scatter(x,y,200,'r','filled'); 

%% bar and barh plots
rm = randi([1 50],2,4);
bar(rm)

%% 
bar(rm,'stack')


%%
barh(rm)

%% Histograms
vec = randi([1 10],1,12);
hist(vec)

%% pie charts
pie(vec)

%% Three-dimensional plot with
% plot 3d
x = 1:5;
y = [0 -4 3 12 5];
z = 2:2:10;
plot3(x,y,z,'k*')
grid

%% bar 3d
x = 1:6;
y = [30 14 4 10 25 31];
bar3(x,y)

%% pie 3d
pie3([3 10 5 2])

%% Subplot to show plot types
x = 1:6;
y = [33 11 5 9 22 30];
subplot(2,2,1)
bar(x,y)
title('bar')
subplot(2,2,2)
barh(x,y)
title('barh')
subplot(2,2,3)
area(x,y)
title('area')
subplot(2,2,4)
stem(x,y)
title('stem')



%% example of deleting column (class example)

A = randi(3,5)
n=4;

B=deletecolumn(A,n)

%  clear A and run the function and see what happens
clear A
B =deletecolumn(B,1)
% and again
B =deletecolumn(B,1)



% 
theta = [0:10^-4:2*10];
plot(theta.*cos(theta),theta.*sin(theta))


%
fplot(@sin,[-10,10])

y=@sin
y(pi)
y(pi/2)


% y = x.sin(x).e(-x^2)

y = @(x)sin(x).*x.*exp(-x.^2)
fplot(y,[-1,1])

% compute the integral from 0 to 1 


myintegral(y,10^-6,0,1)

% integrate x^2
% between -1 and 1

myintegral(@(x)x.^2,10^-6,-1,1)

myintegral(@(x)ones(size(x)),0.01,0,2)


