## Created by Nikola Kuzmanovski ######################################################################## DOCUMENT(); loadMacros( "PGstandard.pl", "MathObjects.pl", "parserMultiAnswer.pl", ); # Print problem number and point value (weight) for the problem TEXT(beginproblem()); # Show which answers are correct and which ones are incorrect $showPartialCorrectAnswers = 1; ############################################################## # # Setup # # Context("Numeric"); Context()->variables->add(t => "Real"); Context()->flags->set( tolerance => 0.0001, tolType => "absolute", ); Context()->strings->add(U=>{}); Context()->strings->add(F=>{}); #Random constants for problem. $I = random(1000, 10000, 1); $cont= random(1,4, 0.1); $comp = random(1,4, 0.13); #Correct answers $correctU = Formula("$I*e^(($cont/100)*t)"); #Depends on I and cont $correctF = Formula("$I*(1+ ($comp/100)/4)^(4*t)"); #Depends on I and comp $correctURate = Formula("e^($cont/100)-1"); #Depends on cont $correctFRate = Formula("(1+($comp/100)/4)^4-1"); #Depends on comp $correctChoice = "U"; #URate is better by default #If FRate is better than F is the correct choice. if ((exp(1))**($cont/100)-1 < (1+($comp/100)/4)**4-1){ $correctChoice = "F"; } #Multi answer checker with partial credit. $multians = MultiAnswer($correctU, $correctF, $correctURate, $correctFRate, $correctChoice)->with( singleResult => 0, allowBlankAnswers => 1, checkTypes => 0, checker => sub { my ( $correct, $student, $self ) = @_; my ( $stuU, $stuF, $stuURate, $stuFRate, $stuChoice ) = @{$student}; #Get student input my ( $U, $F, $URate, $FRate, $choice ) = @{$correct}; #Get correct answers my @ret = (0.0, 0.0, 0.0, 0.0, 0.0); #Points for each correct answer #See if the first formula is correct #If there is some issue with the student input we just move on. #An issue with the student input is anything that will throw an exception. #The eval block will handle any exceptions and not crash the answer checker. eval{ #Get the student I and cont. #We define I by evaluation at 0. #Definition of cont is more complicated, but same idea. my $stuInitialValU = $stuU->eval(t=>0); #Student I my $stuUContRate = log(($stuU->eval(t=>1))/$stuInitialValU); #Student cont #If student got I correct, we give them half the points. if( $I == $stuInitialValU) { $ret[0] = $ret[0] + 0.5; } #If student got cont correct we give them the rest of the points. if ( $cont/100 == $stuUContRate) { $ret[0] = $ret[0] +0.5; } } or do { #Find a way to show some error message to student that might be helpful }; #See if the second formula is correct #If there is some issue with the student input we just move on. #An issue with the student input is anything that will throw an exception. #The eval block will handle any exceptions and not crash the answer checker. eval{ #Get the student I and comp. #We define I by evaluation at 0. #Definition of comp is more complicated, but same idea. my $stuInitialValF = $stuF->eval(t=>0); #Student I my $stuFGrothFactor = ($stuF->eval(t=>1)/$stuInitialValF); #Student comp growth factor #If student got I correct, we give them half the points. if ( $I == $stuInitialValF ) { $ret[1] = $ret[1] + 0.5; } #If student got cont correct we give them the rest of the points. if ( (1+($comp/100)/4)**4 == $stuFGrothFactor ) { $ret[1] = $ret[1] +0.5; } } or do { #Find a way to show some error message to student that might be helpful }; #Check if the effective rate for U bank is correct. #This answer depends on the formula U(t) the student gave #Effective annual reate is growth factor -1. #The growth factor is the base of t. eval{ my $stuInitialValU = $stuU->eval(t=>0); #Student I my $stuUContRate = log(($stuU->eval(t=>1))/$stuInitialValU); #Student growth rate #Check if the student effective rate is correct based on their formula for U. if ( $stuURate == Compute("e^($stuUContRate) - 1")) { $ret[2] = 1; } } or do { #Find a way to show some error message to student that might be helpful }; #Check if the effective rate for F bank is correct. #This answer depends on the formula F(t) the student gave #Effective annual reate is growth factor -1. #The growth factor is the base of t. eval{ my $stuInitialValF = $stuF->eval(t=>0); #Student I my $stuFGrothFactor = ($stuF->eval(t=>1)/$stuInitialValF); #Student growth factor #Check if the student effective rate is correct based on their formula for F. if ( $stuFRate == Compute("$stuFGrothFactor -1")) { $ret[3] = 1; } } or do { #Find a way to show some error message to student that might be helpful }; #Check if student made correct choice for a bank based on their input. if ( ($stuURate > 0 && $stuFRate > 0) && ( ($stuURate < $stuFRate && $stuChoice == "F") || ($stuURate > $stuFRate && $stuChoice == "U") )){ $ret[4] = 1; } return [ @ret ]; } ); ############################################################## # # Text # # Context()->texStrings; BEGIN_TEXT Loretta is trying to determine which bank she should open a savings account at. Loretta plans to make an initial deposit of $$I, and plans to use this money to make a down payment on a house sometime in the undisclosed future. $BR $BR Union Bank offers an account with a nominal annual rate of $cont%, compounded continuously. $BR First National Bank offers an account with a nominal annual rate of $comp%, compounded quarterly. $BR $BR a) Write down the function that gives the amount of money Loretta will have in t years if she uses the Union Bank account. $BR \(U(t) = \) \{ans_rule(50)\}. $BR $BR b) Write down the function that gives the amount of money Loretta will have in t years if she uses the First National Bank account. $BR \(F(t) = \) \{ans_rule(50)\}. $BR $BR c) Compute the effective annual rate of both banks. $BR Effective annual rate for Union Bank: \{ans_rule(50)\}%. $BR Effective annual rate for First National Bank: \{ans_rule(50)\}%. Which Bank will make Loretta more money? Enter U for Union bank. Enter F for First National Bank. $BR \{ans_rule(1)\} END_TEXT Context()->normalStrings; ############################################################## # # Answers # # ANS($multians->cmp()); ENDDOCUMENT();