Physics equations/07-Work and Energy/Q:cart1/history

This quiz is different because it also runs on GNU Octave

edit

This quiz was one of the first wikiquizzes, created so inartfully using Excel that it was impossible to add to the initial three versions that were used at the time.

The reader may note that this quiz uses scientific notation in exponential form using three digits E001 instead of MatLabs customary E01. This testbank was the first to created by GNU Octave (months after a quiz-making program was written for MatLab). Octave is the open source alternative to MatLab that is more difficult to use because its GUI is not user-friendly. For that reason, as of November 2014, there are no immediate plans to use Octave to develop more wikiquizzes. However at some point, it would be nice if open source tests were written using open source software. (Also, it might be better to use another open source language such as Python or Ruby).

To run this code in Octave, put these two files into one folder and run main.m. For more information visit MATLAB/Octave and MATLAB/Wikiquiz_writer_(MATLAB).

testeditor.m

edit
function [ wikiName, wikiHeadABC, wikiHeadD_Z,wikiFirst, wikiCell, wikiMatrix, wikiType] = testeditor(  ) %NO EDIT
%% Change the following lines as needed:
wikiName='pe07-Cart1'; %Name of wikiquiz
wikiHeadABC='[[/testbank/]]   ' ; %What follows is long, so we concatenate:
wikiHeadABC=[wikiHeadABC '[http://www.wright.edu/~guy.vandegrift'];
wikiHeadABC=[wikiHeadABC '/openstaxphysics/quiz_solutions/quiz_solutions.htm'];
wikiHeadABC=[wikiHeadABC ' Solutions to many wikiquiz questions (pdf)]'] ; 
wikiHeadD_Z='Testbank';%'[[Category:Physics_equations/Testbanks]]';
wikiFirst='noIntroLine';% (If 'noIntroLine' there is no introductory line)
wikiType =1;%Set wikiType to 1 or 2
%   If WikiType=1, wrong answers are 
%       multiplied by 10^(n/N) where n is a small integer and N=wikiDR
%   If WikiType=2, wrong answers are 
%       larger by n*N where n is a small integer and N=wikiDR
%               
wikiQI=0; %NO EDIT  (counts the questions)
%
% Copy and paste from %%BEGIN QUESTION%% to %%END QUESTION%% as needed
%% BEGIN QUESTION 1%%
wikiS='If the initial velocity after leaving the spring is '; % S0 DONE
wikiV=randi([21,99])/10;  v=wikiV ; % V1 DONE (inserted earlier to test: wikiV=5;)
wikiS= [wikiS num2str(wikiV)];  %V2 DONE
wikiS=[wikiS,' m/s, how high does it reach before coming to rest?']; % S1 DONE
wikiS=[wikiS,'[[File:Roller coaster energy conservation.jpg|right|280px]]']; % S1 DONE
answer=v^2/2/9.8; 
wikiA =answer; 
wikiU =' m';
wikiDR = 12; 
wikiSigfig=2;
wikiQI=wikiQI+1;wikiCell{wikiQI,1}=wikiS;wikiCell{wikiQI,2}=wikiU; 
wikiMatrix(wikiQI,:)=[wikiA wikiDR wikiSigfig]; 
%% BEGIN QUESTION 2%%
wikiS='The mass of the cart is '; % S0 DONE
wikiV=randi([21,99])/10;  m=wikiV ; % V1 DONE (Inserted earlier to test: wikiV= 2;
wikiS= [wikiS num2str(wikiV)]; % V2  DONE
wikiS=[wikiS,'kg, and the spring constant is ']; % S1 DONE
wikiV=randi([4001,9999]);  k=wikiV; % V1  DONE  (Inserted earlier to test: wikiV=5447;
wikiS= [wikiS num2str(wikiV)]; % V2  DONE  (Inserted earlier to test: 
wikiS=[wikiS 'N/m. If the initial compression of the spring is ']; % S1 DONE
wikiV=randi([1,7])/10;  L=wikiV; % V1    DONE (Inserted earlier to test: wikiV=0.1;
wikiS= [wikiS num2str(wikiV)]; % V2 DONE
wikiS=[wikiS 'm, how high does it reach before coming to rest? ' ];  % S1 DONE
wikiS=[wikiS,'[[File:Roller coaster energy conservation.jpg|right|280px]]']; % S1 DONE
answer=k*L^2/2/m/9.8; %  use as many lines as you need to obtain wikiA:
wikiA =answer; % wikiA =  answer (reserved)
wikiU =' m';% wikiU = units (reserved)
wikiDR = 12; % wikiDR = detractor ratio is wikType=1 (reserved) DONE
wikiSigfig=2;% wikiSigfig = sig figs (reserved)
%Housekeeping  (do not edit)
wikiQI=wikiQI+1;wikiCell{wikiQI,1}=wikiS;wikiCell{wikiQI,2}=wikiU; %Do not edit
wikiMatrix(wikiQI,:)=[wikiA wikiDR wikiSigfig]; %Do not edit D
%%% BEGIN QUESTION 3%%
wikiS='What is the highest point the cart reaches if the speed was '; % S0 
wikiV=randi([65,85])/10;  v1=wikiV ; % V1 DONE  (Inserted earlier to test: wikiV=.14;
wikiS= [wikiS num2str(wikiV)]; % V2 
wikiS=[wikiS,'m/s when the cart was situated at a height of ']; % S1
wikiV=randi([11,31])/10;  h1=wikiV; % V1  DONE  (Inserted earlier to test:  wikiV=2.2;
wikiS= [wikiS num2str(wikiV)]; % V2 
wikiS=[wikiS 'm? ']; % S1
wikiS=[wikiS,'[[File:Roller coaster energy conservation.jpg|right|280px]]']; % S1 DONE
answer=h1+v1^2/2/9.8; %  use as many lines as you need to obtain wikiA:
%h1overSum=h1/answer
wikiA =answer; % wikiA =  answer (reserved)
wikiU =' m';% wikiU = units (reserved)
wikiDR = 14; % wikiDR = detractor ratio is wikType=1 (reserved)
wikiSigfig=2;% wikiSigfig = sig figs (reserved)
%Housekeeping  (do not edit)
wikiQI=wikiQI+1;wikiCell{wikiQI,1}=wikiS;wikiCell{wikiQI,2}=wikiU; %Do not edit
wikiMatrix(wikiQI,:)=[wikiA wikiDR wikiSigfig]; %Do not edit
%
end % NO EDIT (must follow last question)

main.m

edit
function [void]=main(void) %NO EDIT
%MAIN is the program you run to create the wikiquizzes after
%numericWiki.m has been suitably modified.  But you do not edit MAIN.
% variable list (may be outdated) %NO EDIT
% wikiMatrix(answer,wikiDR,wikiSigFig) %NO EDIT
% wikiType = 1 most of the time.%NO EDIT
% WikiSigFig is called sf in bookeeping.%NO EDIT
%
[ wikiName, wikiHeadABC,wikiHeadD_Z, wikiFirst, wikiCell, wikiMatrix, wikiType] = testeditor(  );%NO EDIT
cellsofar{1,1}=wikiHeadABC;%%NO EDIT First line of a wikiquiz
for index=65:67%NO EDIT
[ wikiName, wikiHeadABC,wikiHeadD_Z, wikiFirst, wikiCell, wikiMatrix, wikiType] = testeditor(  );%NO EDIT
cellsofar=startonequiz(wikiName,char(index) , wikiFirst, cellsofar);% ... <quiz display=simple>
cellsofar=finishthequiz(wikiMatrix,wikiCell,1, cellsofar);% ... </quiz>
printafile([wikiName 'ABC'],cellsofar);%NO EDIT
end%NO EDIT
clear cellsofar;%NO EDIT
cellsofar{1,1}=wikiHeadD_Z;%First line of a wikiquiz
%NO EDIT
for index=68:90%NO EDIT
[ wikiName, wikiHeadABC,wikiHeadD_Z, wikiFirst, wikiCell, wikiMatrix, wikiType] = testeditor(  );%NO EDIT
cellsofar=startonequiz(wikiName,char(index) , wikiFirst, cellsofar);% ... <quiz display=simple>
cellsofar=finishthequiz(wikiMatrix,wikiCell,1, cellsofar);% ... </quiz>
printafile([wikiName 'D_Z'],cellsofar);%NO EDIT
end%NO EDIT
%NO EDIT
%%% functions %%%%%NO EDIT
    function [cellsofar]=finishthequiz(wikiMatrix,wikiCell,wikiType, cellsofar)%NO EDIT
        % FINISHTHEQUIZ finishes a wikiquiz with </quiz>
        nQues=size(wikiMatrix,1);%NO EDIT
        for iQues=1:nQues%NO EDIT
            cellsofar{size(cellsofar,1)+1,1}=['{',char(wikiCell(iQues,1)),'}'];%NO EDIT
            anspos = randi([1,5]);%NO EDIT
            for iAns=1:5%NO EDIT
                lett=char(96+iAns);%NO EDIT
                if iAns==anspos%NO EDIT
                    key = '+';%NO EDIT
                else%NO EDIT
                    key = '-';%NO EDIT
                end%NO EDIT
                s=[key,lett,') '];%NO EDIT
                %%%%%%%%The default is wikiType =1%%%%%%%%%NO EDIT
%This default multiplies the answer by 10^(n/N) where N=wikiDR=wikiMatrix(:,2)                 
                if wikiType ==1%NO EDIT
                ef=10^((iAns-anspos)/wikiMatrix(iQues,2));%NO EDIT
                sf=num2str(wikiMatrix(iQues,3)); % = wikiSigFig in testeditor
                form=['%.' sf 'E'];%NO EDIT
                num = num2str(ef*wikiMatrix(iQues,1),form);%NO EDIT
                end%NO EDIT
                %%%%%%%%%%%%%% wikiType not yet incorporated%%%%%%%%
              if wikiType==2%NO EDIT
                ef=iAns-anspos; %ef is now what is added or subtracted 
                sf=num2str(WikiMatrix(iQues,3));%NO EDIT
                form=['%6.' sf 'f'];  % now floating point
                num = num2str(ef+WikiMatrix(iQues,1),form);%NO EDIT
              end %NO EDIT
                %end copy to below
                %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                s=[s num ' ' char(wikiCell(iQues,2))];%NO EDIT
                cellsofar{size(cellsofar,1)+1,1}=s;%NO EDIT
            end%NO EDIT
            cellsofar{size(cellsofar,1)+1,1}= '  ' ;%NO EDIT
        end%NO EDIT
            cellsofar{size(cellsofar,1)+1,1}= '</quiz>  ' ;%NO EDIT
        end%NO EDIT
    end%NO EDIT
%NO EDIT
    function [cellsofar]=startonequiz(wikiName, letter ,wikiFirst,cellsofar)%NO EDIT
        %STARTONEQUIZ adds: ==wikiName letter==    wikifirst   <quiz...
        % cellsofar is appended to original cellsofar
        string = ['==' wikiName ' ' letter '=='];%NO EDIT
        cellsofar{size(cellsofar,1)+1,1}=string;%NO EDIT
        if ~strcmp(wikiFirst,'noIntroLine');%NO EDIT
            cellsofar{size(cellsofar,1)+1,1}=wikiFirst;%NO EDIT
        end%NO EDIT
        cellsofar{size(cellsofar,1)+1,1}= '<quiz display=simple>';%NO EDIT
    end%NO EDIT
    function []=printafile(filename,cellsofar)%NO EDIT
        %PRINTAFILE makes a txt file with the name filename that contains the cell array cellsofar
        fout=fopen([filename '.txt'], 'w+');%NO EDIT
        for count=1:size(cellsofar,1)%NO EDIT
            string=char(cellsofar(count,1));%NO EDIT
            fprintf(fout,'%s\n',char(string));%NO EDIT
        end%NO EDIT
        fclose(fout);%NO EDIT
    end%NO EDIT