% Script for introduction to basic Matlab commands
% The commands introduced in this script are sufficient to understand the
% 2D finite element code distributed in this lecture
% 
% Stefan Schmalholz, ETH Zurich, October 2008
clear variables, close all, clc

disp(' ')
disp('__________________________________________________________________________________________________________________')
disp(' ')
disp('This is a script introducing basic Matlab commands needed for the course "Numerical modelling of rock deformation".')
disp('The introduced commands are sufficient to understand the 2D finite element code distributed in this lecture.')
disp('The commands are shown as a display and after you press Enter the results appear on the command line.')
disp(' ')
disp('An extensive documentation can be found on www.mathworks.com/support')
disp(' ')

%==========================================================================
disp(' ')
disp('1) Basic calculations')
disp('---------------------')
disp('Command: ">>4+2" (press Enter to see the result of this command)'); pause
4+2
disp('Command: ">>4*2" (press Enter to see the result of this command)'); pause
4*2
disp('Command: ">>4/2" (press Enter to see the result of this command)'); pause
4/2
disp('Command: ">>4^2" (press Enter to see the result of this command)'); pause
4^2

%==========================================================================
disp('Done with 1) Press enter to continue')
pause
clc

disp(' ')
disp('2) Basic vector and matrix definitions and calculations')
disp('-------------------------------------------------------')

disp('Command: ">>A=[1 2 3 4 5]" (press Enter to see the result of this command)'); pause
A=[1 2 3 4 5]
disp('Command: ">>A=[1;2;3;4;5]" (press Enter to see the result of this command)'); pause
A=[1;2;3;4;5]
disp('Command: ">>A=[1 2;3 4;5 6]" (press Enter to see the result of this command)'); pause
A=[1 2;3 4;5 6]
disp('Command: ">>A=[1 2 3 4 5]" (press Enter to see the result of this command)'); pause
A=[1 2 3 4 5]
disp('Command: ">>B=[1 2 3 4 5]" (press Enter to see the result of this command)'); pause
B=[1 2 3 4 5]
disp('Command: ">>A.*B" (press Enter to see the result of this command)'); pause
A.*B
disp(['Command: ">>A*transpose(B) (press Enter to see the result of this command)']); pause
A*transpose(B)
disp(['Command: ">>transpose(A)*B (press Enter to see the result of this command)']); pause
transpose(A)*B
disp(['Command: ">>A=[1 2 4; 3 2 1; 2 2 2] (press Enter to see the result of this command)']); pause
A=[1 2 4; 3 2 1; 2 2 2]
disp(['Command: ">>B=[1;2;1] (press Enter to see the result of this command)']); pause
B=[1;2;1]
disp(['Command: ">>A*B (press Enter to see the result of this command)']); pause
A*B
disp(['Command: ">>B=[1 1; 2 2; 3 3] (press Enter to see the result of this command)']); pause
B=[1 1; 2 2; 3 3]
disp(['Command: ">>A*B (press Enter to see the result of this command)']); pause
A*B
disp(['Command: ">>B=[1 1; 2 2; 3 3] (press Enter to see the result of this command)']); pause
B=[1 1; 2 2; 3 3]
disp(['Command: ">>B=reshape(B,1,6) (press Enter to see the result of this command)']); pause
B=reshape(B,1,6)
disp(['Command: ">>B=reshape(B,3,2) (press Enter to see the result of this command)']); pause
B=reshape(B,3,2)
disp(['Command: ">>B=[2 3; 1 4] (press Enter to see the result of this command)']); pause
B=[2 3; 1 4]
disp(['Command: ">>B_inv=inv(B) (press Enter to see the result of this command)']); pause
B_inv=inv(B)
disp(['Command: ">>B_det=det(B) (press Enter to see the result of this command)']); pause
B_det=det(B)
disp(['Command: ">>help det (press Enter to see the result of this command)']); pause
help det
disp(['Command: ">>K=[1 0; 0 1] (press Enter to see the result of this command)']); pause
K=[1 0; 0 1]
disp(['Command: ">>Ks=spdiags(K) (press Enter to see the result of this command)']); pause
Ks=spdiags(K)

%==========================================================================
disp('Done with 2) Press enter to continue')
pause
clc

disp(' ')
disp('3) Basic loops')
disp('--------------')
disp('Command: ">>for i=1:3; i, end" (press Enter to see the result of this command)'); pause
for i=1:3; i, end
disp('Command: ">>for i=1:3; a=i^2, end" (press Enter to see the result of this command)'); pause
for i=1:3; a=i^2, end
disp('Command: ">>for i=8:-2:0; i, end" (press Enter to see the result of this command)'); pause
for i=8:-2:0; i, end
disp('Command: ">>K=zeros(2,2)" (press Enter to see the result of this command)'); pause
K=zeros(2,2)
disp('Command: ">>for i=1:2; for j=1:2 K(i,j)=i+j, end, end" (press Enter to see the result of this command)'); pause
for i=1:2; for j=1:2 K(i,j)=i+j, end, end
disp('Command: ">>for i=1:5; i, if i==3; a=i, end, end" (press Enter to see the result of this command)'); pause
for i=1:5; i, if i==3; a=i, end, end

%==========================================================================
disp('Done with 3) Press enter to continue')
pause
clc

disp(' ')
disp('4) Basic plotting')
disp('-----------------')
disp('Command: ">>x=[1:10]" (press Enter to see the result of this command)'); pause
x=[1:10]
disp('Command: ">>y=x.^(1.5)" (press Enter to see the result of this command)'); pause
y=x.^1.5
disp('Command: ">>plot(x,y)" (press Enter to see the result of this command)'); pause
plot(x,y)
disp('Command: ">>y=10-x" (press Enter to see the result of this command)'); pause
y=10-x
disp('Command: ">>plot(x,y)" (press Enter to see the result of this command)'); pause
plot(x,y)
disp('Command: ">>y=cos(2*pi*x/max(x))" (press Enter to see the result of this command)'); pause
y=cos(2*pi*x/max(x))
disp('Command: ">>plot(x,y)" (press Enter to see the result of this command)'); pause
plot(x,y)
disp('Command: ">>y=x" (press Enter to see the result of this command)'); pause
y=x
disp('Command: ">>[X2d,Y2d]=meshgrid(x,y)" (press Enter to see the result of this command)'); pause
[X2d,Y2d]=meshgrid(x,y)
disp('Command: ">>plot(X2d,Y2d)" (press Enter to see the result of this command)'); pause
plot(X2d,Y2d)
disp('Command: ">>hold on" (press Enter to see the result of this command)'); pause
hold on
disp('Command: ">>plot(transpose(X2d),transpose(Y2d))" (press Enter to see the result of this command)'); pause
plot(transpose(X2d),transpose(Y2d))
disp('Command: ">>hold off" (press Enter to see the result of this command)'); pause
hold off
disp('Command: ">>S=Y2d.^(1/2)" (press Enter to see the result of this command)'); pause
S=Y2d.^(1/2)
disp('Command: ">>pcolor(X2d,Y2d,S); shading interp; colorbar" (press Enter to see the result of this command)'); pause
pcolor(X2d,Y2d,S); shading interp; colorbar

%==========================================================================
disp('Done with 4) Press enter to continue')
pause
clc

disp(' ')
disp('5) Equation solving')
disp('-------------------')
disp('Command: ">>K=[1 2; 3 1]" (press Enter to see the result of this command)'); pause
K=[1 2; 3 1]
disp('Command: ">>f=[8;9]" (press Enter to see the result of this command)'); pause
f=[8;9]
disp('Command: ">>u=K\f" (press Enter to see the result of this command)'); pause
u=K\f

%==========================================================================
disp(' ')
disp('---------------------------------------------------------------------')
disp('FINISH')
disp('---------------------------------------------------------------------')
