To try out a few other vector operations, type <strong>in</strong>cleara = [1, 2, 3]b = [2, 3, 4]and then type <strong>in</strong> each of the follow<strong>in</strong>g quantities and hit enter:a*b’ a’*b dot(a,b)dot(a,b’) cross(a,b) cross(a’,b’)Notice that the dot function does not dist<strong>in</strong>guish betweencolumn vectors and row vectors but that the other operationsdo.FunctionsThe third and f<strong>in</strong>al template shows you how to createfunctions. This will help you become more efficient <strong>in</strong>programm<strong>in</strong>g. Create the M-file called tfunction.m and type <strong>in</strong>Table 3. The M-file tfunction.m turns the force reactions <strong>in</strong> thesecond template <strong>in</strong>to a function of beta and theta. In thecommand w<strong>in</strong>dow, type <strong>in</strong>[F,NA]=tfunction(pi/6,pi/4)and hit enter. The reactions F and N A are displayed.6
function [F,NA] = tfunction(beta,theta)%% tfunction.m%% This m-file is a template for a function.%% In this template, the function tfunction f<strong>in</strong>ds the friction force F and the normal% force NA.% The <strong>in</strong>puts to the function are the variables beta (the angle of the bar) and theta% (the angle of the <strong>in</strong>cl<strong>in</strong>e). These two <strong>in</strong>puts are <strong>in</strong> radians.% The outputs to the function are F and NA.% Notice the syntax for the function. The output variables are surrounded by brackets,% the <strong>in</strong>put variables are surrounded by parentheses, and the name of the function is% the same as the name of the file.%% This template shows:%% - the syntax for a function%W = 100;L = 2;b = [W,0,W*L/2*cos(beta)]';A = [0,1,cos(theta);1,0,-s<strong>in</strong>(theta);0,0,L*cos(theta-beta)];a<strong>in</strong>v = <strong>in</strong>v(A);x = a<strong>in</strong>v*b;F = x(1);NA = x(2);Table 3: Template for FunctionsThe M-file tfunction.m can also be called from with<strong>in</strong>another program. So can the M-files test1 and test2. Toillustrate this, create the M-file named test2.m and type <strong>in</strong>Table 4. This program determ<strong>in</strong>es the critical angle beta of thebar for which the bar rema<strong>in</strong>s <strong>in</strong> static equilibrium but belowwhich the bar slides (See Fig. A2 – 2). The program test2.mcalls the function tfunction.m <strong>in</strong> a loop, sweep<strong>in</strong>g over a rangeof values of beta between 0 and theta. Each time the function iscalled, the program compares the value of the friction forcewith the maximum allowable level of friction, F max = µN A , tosee if it’s been exceeded. To run test2.m, go to the commandw<strong>in</strong>dow, type <strong>in</strong>test2and hit enter. The command w<strong>in</strong>dow displaysbetacritical = 26.55, which is the critical angle beta<strong>in</strong> degrees, and a figure w<strong>in</strong>dow appears show<strong>in</strong>g two graphs.One graph is of the friction force F versus beta and the secondgraph is of the maximum friction force (above which the barslides) versus beta.Figure A2 – 2: A bar rests on a rough surface at oneend and on a smooth <strong>in</strong>cl<strong>in</strong>ed surface at the other end.7