% ---------------------- % USEFUL MATLAB COMMANDS % ---------------------- % -------- % vectors: % -------- x=[0:0.2:1], x1=[0, 0.2, 0.4, 0.6, 0.8, 1], x2=[0 0.2 0.4 0.6 0.8 1] % row z=[0; 0.2; 0.4; 0.6; 0.8; 1] % column x(2), z(2) y=transpose(x) y*x x*y % not defined: % y.*x sin(x) sin(x(2)) % --------- % matrices: % --------- z1=zeros(3), z2=zeros(2,4) m=[1 2; 3 4] m1=[1 2 3 4] transpose(m) m^2 n=inv(m) n*m % compare with component-wise multiplication: n.*m det(m) eig(m) [v,lambda]=eig(m) v1=v(:,1) check=m*v1-lambda(1,1)*v1 m=[1 0 0 2] k=[ 1 -1 -1 1] omega2=eig(k,m), omega=sqrt(omega2) check=det(k-omega(1)^2.*m) a=rand(4) a1=a([1:3],[1:3]) a2=a([1:2],4) a3=a([1,3],[2,4]) % call function 'beam' (defined in 'beam.m'; see below): % s=zeros(8); k=beam(1,1) % % add beam element 1: % s([1 2 3 4],[1 2 3 4])=s([1 2 3 4],[1 2 3 4])+k % % add beam element 2: % s([3 4 5 6],[3 4 5 6])=s([3 4 5 6],[3 4 5 6])+k % % add beam element 3: % s([5 6 7 8],[5 6 7 8])=s([5 6 7 8],[5 6 7 8])+k % ---------- % functions: % ---------- t=[0:0.1:2*pi]; plot(sin(t)) plot(t,sin(2*t).^2,t,sqrt(t)) integral=quad('sin(2*y)',0,2*pi) fzero('x-tan(x)',2), fzero('x-tan(x)',4) % ------------------- % logical structures: % ------------------- x=0 for i=1:2:10 x=x+i end i=input('Enter first number: '); j=input('Enter second number: '); % if i==j r=1 elseif abs(i-j)>=2 r=2 elseif i~=0 & j~=0 r=1/(i*j) end % ------------------------------ % contents of the file 'beam.m': % ------------------------------ % %function k=beam(EI,L) % %k = (EI/L^3)*[ 12 6*L -12 6*L % 6*L 4*L^2 -6*L 2*L^2 % -12 -6*L 12 -6*L % 6*L 2*L^2 -6*L 4*L^2 ];