% % my first matlab script % (note the "percent" signs indicate non-executed comment lines) % % save as: "wilk.m" % % to run: type "wilk" at the matlab prompt (note: you may have to set % the directory/folder into the matlab path), or use the "run" menu % choice (not sure of exact PC name of run script menu choice). % % browser help: type "helpdesk" at the matlab prompt % % instant help: type "help xxxx" for help about command xxxx % (try "help clf", etc) % %- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - % define some parameters N = 7; a = 0.00002; % define a vector of x-values x = 0:0.025:N+1; % loop to evaluate y1(x) = (x-1)(x-2)...(x-N) y1 = ones(size(x)); for j=1:N y1 = y1.*(x-j); end % evaluate y2(x) % (note "." denote element-wise operation: "help arith") y2 = a*N*(N+1)/2*x.^(N-1); % make a LABELLED plot clf plot(x,y1,'b'); hold on; plot([0 N+1],[0 0],'k') plot(x,y2,'r--') axis([0 N+1 -100 200]) title('\bf wilkinson''s example') xlabel('\bf x-axis (in boldface)') ylabel('y-axis (not in \bf boldface\rm)') text(3,100,'roots are where blue & red curves cross') disp('check out: exercise 2, page 23 of holmes')