% Script File: ShowTextAlignment % How to place text relative to a coordinate point. close all HA = 'HorizontalAlignment'; HV = 'VerticalAlignment'; figure plot(0,0,'*') axis([-1 1 -1 1]) axis equal square set(gca,'xTick',[-1 0 1],'yTick',[-1 0 1]) grid o
function [positions, trueNames] = usaData2() % Data for CityGame. Full version with just n=26 cities. % positions: x and y coordinates of n cities in an n-by-2 matrix % trueNames: cell array of length n containing the names of n cities % So positions(i,1)
function p = AandC(n) % p is the probability of both case A and case C occurring when drawing one % card from a standard deck. % n is the number of trials a = 0; for k = 1:n; [rk, st] = OneCard(); if (rk = 11 | rk = 12 | rk = 13) & (st = 2 | st = 3) a = a
function p % p is the % from a % n is the a = 0;
= AorB(n) probability of case A or case B occurring when drawing one card standard deck. number of trials.
for k = 1:n; [rk, st] = OneCard(); if rk = 11 | rk = 12 | rk = 13 | (st = 2 | st = 3) & (rk = 9 | r
function [x] = vectorQuery(v,n,r) 0etermine whether the number r appears in the first n cells of vector v. %The function returns 1 if r is in the first n cells of v and 0 otherwise a = 0; if n <= length(v) for k = 1:n if v(k) = r a = a + 1; end end else f
% Script areaCircle % Convergence of polygons to unit circle by area. % Print the column headings fprintf('\n n\t inner n-gon outer n-gon\n'); fprintf('-\n'); n= 3; innerA= (n/2)*sin(2*pi/n); outerA= n*sin(pi/n)/cos(pi/n); tol= 0.01; % area of inscribed n
function [positions, trueNames] = usaData1() % Data for CityGame. Short version with just n=5 cities. % positions: x and y coordinates of n cities in an n-by-2 matrix % trueNames: cell array of length n containing the names of n cities % So positions(i,1)
a = input('Enter number between 0-180 '); b1 = 180 - a b = input('Enter number between 0 and b1 ' ); c = 180 - b - a; if (a<90 & b<90 & c<90) disp('acute') elseif (a = 90 | b = 90 | c = 90) disp('right') else disp('obtuse') end
% Script File: ShowTicks % How to set and label axis ticks. close all x = linspace(0,4*pi); y = sin(x); plot(x,y) axis([0 4*pi -1.2 1.2]) % Define x-ticks and their labels. set(gca,'xTick',0:pi/2:4*pi) set(gca,'xTickLabel',cfw_'0', ' ', 'pi', ' ', '2pi',
% Script File: ShowWindowColor % How to color the figure window and surrounding area. close all figure % Draw a magenta plot window. set(gca,'color','m') % Draw the surrounding area yellow. set(gcf,'color','y')
A = getLeslieMatrix(6); v = [5;0;0;0;0;0;0]; population = ; textArray= cell(7,1); hold all for k = 1:50; v = matVecMult(A, v); Qn = sum(v); pop = ; for n = 1:7 frac = v(n)/Qn; pop = vertcat( pop, frac); end population = horzcat(population, pop); end p
function cell = splitString(str, sep) %given a string str and a separating character sep splits str at the places where sep. %returns a cell array of strings containing each of the individual pieces of the %original str but not including the occurrences o
% % % % %
Script stepPyramid.m Draw a step pyramid with a base rectangle of L-by-H where H<=L. Each step has the same height H. The next rectangle up is 2/3 the width of the rectangle below, and so forth. The top step must have a length no less than H.
function timeClock(h,m,s) % Display the time h:m:s on a clock with hour and minute hands. % Hour h may be in 12- or 24-hour clock format, i.e., range is [0.24]. % Minute m and second s are in the range [0.59]. drawClockFace('d','.'); % Draw hour hand hour
function up= toUpper(cha) % up is the upper case letter corresponding to lower case letter cha. % If cha is not a lower case letter, do not capitalize and up is simply cha. up= cha; if ( cha >= 'a' & cha <= 'z' ) distance= cha - 'a'; % how far cha is from
% % % % %
function xStar = Bisection(f,L,R) f is a handle to a continuous function f(x) of a single variable. L and R define an interval [L,R] and f(L)f(R) < 0 xStar is an approximate root of f with the property that it is within |R-L|/10^6 of a true root
function vgen = writeVdata(sfile, vfile, L, q) % Write length L palindrome-type virus data to a plain text file. % sfile names the genome data file. The file contains multiple lines of % data in plain text. % vfile names the virus data file to be written.
function drawClockFace(hourSymbol, minsSymbol) % Draw a clock face where the hours and minutes are marked. % hourSymbol, minsSymbol are CHARACTERS representing the marker type % used in a plot statement. Possibilities include: % '.' 'o' 'x' '+' '*' % Type
% Adds a circular disk to the current window.
% Assumes hold is on.
% The disk has radius r, center(xc,yc) and
% color c where c is one of 'r', 'g', 'y', etc.
theta = linspace(0,2*pi);
cosVals = cos(theta);
sinVals = sin(theta
% % % %
function DrawRect(a,b,L,W,c) Adds a rectangle to the current window. Assumes hold is on. The rectangle has vertices (a,b), (a+L,b), (a+L,b+W), and (a,b+W) and color c where c is one of 'r', 'g', 'y', etc. x = [a a+L a+L a a]; y = [b b b+W b+W b];
% Script Eg3_1 % Plots the function f(x) = sin(5x) * exp(x/2) / (1 + x^2) % on the interval [-2,3]. L R N x = -2; % Left endpoint = 3; % Right endpoint = 200; % Number of sample points = linspace(L,R,N);
% Vector of f-evaluations y = sin(5*x) .* exp(-x/2)