diff --git a/Contrib/TRU/README.md b/Contrib/TRU/README.md new file mode 100644 index 0000000000..23a09533b2 --- /dev/null +++ b/Contrib/TRU/README.md @@ -0,0 +1,3 @@ +Thompson Rivers University Problem Authors: + +Kyle Schlitt; email kschlitt@tru.ca; GitHub: kyleschlitt diff --git a/Contrib/TRU/math1070/comparingSimpleCompound.pg b/Contrib/TRU/math1070/comparingSimpleCompound.pg new file mode 100644 index 0000000000..3754a3f5be --- /dev/null +++ b/Contrib/TRU/math1070/comparingSimpleCompound.pg @@ -0,0 +1,98 @@ +## DBsubject(Financial mathematics) +## DBchapter(Interest) +## DBsection(Compound interest) +## Level(2) +## KEYWORDS('simple interest rate', 'compound interest') +## Author(Kyle Schlitt) +## Institution(TRU) +## Language(en) + +DOCUMENT(); + +loadMacros( + 'PGstandard.pl', + 'PGML.pl', + 'contextCurrency.pl', + 'parserPopUp.pl' +); + +Context("Currency"); + +Context()->flags->set( + tolerance => 0.01, + tolType => "absolute", +); + +# what is the compounding frequency +@frequencies = (1,2,4,6,12,24,52,365); + +@compounding_type = ( + "annually", + "semi-annually", + "quarterly", + "bi-monthly", + "monthly", + "semi-monthly", + "weekly", + "daily" +); + +do { + $P = Currency(10000 + 1000 * random(0,10,1)); + $t = random(15,20,1); + + $simple_r = 0.07 + 0.01 * random(0,3,1); + $simple_r_percent = $simple_r * 100; + $compound_r = $simple_r - 0.02; + $compound_r_percent = $compound_r * 100; + + $k = random(0,7,1); + $m = $frequencies[$k]; + $m_word = @compounding_type[$k]; + + $n = $m*$t; + $i = $compound_r/$m; + + $simple_amount = $P * (1 + $simple_r*$t); + $simple_interest = $simple_amount - $P; + + $compound_amount = $P * (1 + $i)**($n); + $compound_interest = $compound_amount - $P; + + if ($compound_amount > $simple_amount) { + $correct_choice = "Option #2"; + } else { # unlikely + $correct_choice = "Option #1"; + } + + $final_choice = DropDown( + ["Option #1", "Option #2"], + $correct_choice, + placeholder => "Select One" + ); + +} while ($compound_amount == $simple_amount); + +BEGIN_PGML + +You plan to invest [$P] in a retirement fund for [$t] years, and you are offered two investment options: + +**Option #1:** Simple interest at an annual rate of [$simple_r_percent]%. + +**Option #2:** Compound interest at an annual rate of [$compound_r_percent]%, compounded [$m_word]. + +How much interest will each investment option yield? After comparing the two plans, which option should be chosen? + +---- + +**Answer**: + +Under simple interest, the investment will earn [_]{$simple_interest} in interest, growing to a total of [_]{$simple_amount}. + +Under compound interest, the investment will earn [_]{$compound_interest} in interest, growing to a total of [_]{$compound_amount}. + +[_]{$final_choice} should be chosen. + +END_PGML + +ENDDOCUMENT(); \ No newline at end of file diff --git a/Contrib/TRU/math1070/convenienceStore.pg b/Contrib/TRU/math1070/convenienceStore.pg new file mode 100644 index 0000000000..a55a1c5968 --- /dev/null +++ b/Contrib/TRU/math1070/convenienceStore.pg @@ -0,0 +1,94 @@ +## DBsubject(Algebra) +## DBchapter(Linear equations and functions) +## DBsection(Applications and models) +## Level(2) +## KEYWORDS('supply', 'demand', 'price') +## Author(Kyle Schlitt) +## Institution(TRU) +## Language(en) + +DOCUMENT(); + +loadMacros( + "PGstandard.pl", + "PGML.pl", + "contextCurrency.pl", + "parserImplicitEquation.pl" +); + +$slope_num = -(1 + random(5,20,1)); +$slope_den = 100; +$m = $slope_num/$slope_den; + +$data_q_1 = random(10,20,1); +$data_p_1 = 4 + 0.01*random(0,50,1); + +$b = $data_p_1 - $m*$data_q_1; +$q_intercept = $data_q_1 - $data_p_1/$m; + +$data_q_2 = $data_q_1 + random(4,10,1); +$data_p_2 = $slope_num/$slope_den*($data_q_2 - $data_q_1) + $data_p_1; + +$target_quantity = int($data_q_2 + int(($q_intercept - $data_q_2)/random(2,3,1))); + +$target_price = $m*($target_quantity - $data_q_2) + $data_p_2; + +$specified_price = -1; + +while ($specified_price < 0 || $specified_price == $target_price) { + $random_multiplier = random(5,15,1); + $specified_quantity = $data_q_2 + $random_multiplier; + $specified_price = $data_p_2 + $m * $random_multiplier; +} + +Context("Currency"); + +BEGIN_PGML + +A store-owner is marketing a brand new energy drink at a local convenience store. He observes that [`[$data_q_1]`] cans per day are sold if the price per can is set to [`[@ Currency($data_p_1) @]`], but [`[$data_q_2]`] cans per day are sold if the price is set at [`[@ Currency($data_p_2) @]`] per can. + +Assuming there is a linear relationship between + +* [`p =`] the price per can, and +* [`q =`] the number of cans sold per day, + +find the demand equation, expressed as a relationship between the variables [`p`] and [`q`]. + +END_PGML + +Context("ImplicitEquation"); + +Context()->variables->add(q => 'Real', p => 'Real'); + +Context()->variables->set( + q => { limits => [-10,10]}, + p => { limits => [-10,10]} +); + +$demand_equation = ImplicitEquation("p=$m*q + $b"); + +BEGIN_PGML + +**Answer:** [_]{$demand_equation} + +---- + +END_PGML + +Context("Currency"); + +BEGIN_PGML + +What should the price be set to in order to sell [`[$target_quantity]`] cans per day -- be sure to include units! + +**Answer:** The price should be set to [_]{Currency($target_price)} per can. + +---- + +If the price per can is set to [`[@ Currency($specified_price) @]`], how many cans should the store-owner expect to sell per day? + +**Answer:** The store will sell [_]{$specified_quantity} cans per day. + +END_PGML + +ENDDOCUMENT(); \ No newline at end of file diff --git a/Contrib/TRU/math1070/domainInterceptsRationalFunction.pg b/Contrib/TRU/math1070/domainInterceptsRationalFunction.pg new file mode 100644 index 0000000000..4ee6c61099 --- /dev/null +++ b/Contrib/TRU/math1070/domainInterceptsRationalFunction.pg @@ -0,0 +1,126 @@ +## DBsubject(Algebra) +## DBchapter(Functions) +## DBsection(Graphs) +## Level(2) +## KEYWORDS('domain', 'range', 'intercepts', 'rational function', 'rational functions') +## Author(Kyle Schlitt) +## Institution(TRU) +## Language(en) + +DOCUMENT(); + +loadMacros( + "PGstandard.pl", + "PGML.pl", + "parserMultiAnswer.pl", + "parserPopUp.pl", + "contextFraction.pl" +); + +Context("Fraction"); + +# choose the x-intercepts of f +$xintercept1num = random(1,4,1); +$xintercept1den = 5; +$xintercept1 = Fraction($xintercept1num, $xintercept1den)->reduce; + +$xintercept2 = random(2,5); + +# build the numerator of f so it has the desired xintercepts +$f_num_a = $xintercept1den; +$f_num_b = -($xintercept1den*$xintercept2 + $xintercept1num); +$f_num_c = $xintercept1num*$xintercept2; +$f_num = Compute("$f_num_a x^2 + $f_num_b x + $f_num_c")->reduce; + +# choose the points at which f will not be defined +$singularity1 = random(5,9,1); + +do { + $singularity2 = random(1,7,1); +} while ($singularity2 == $singularity1); + +# build the denominator of f so it has the desired singularities +$f_den_a = 1; +$f_den_b = -($singularity1 + $singularity2); +$f_den_c = $singularity1*$singularity2; + +$f_den = Compute("$f_den_a x^2 + $f_den_b x + $f_den_c")->reduce; + +$f = $f_num/$f_den; + +$popup = DropDown(['a polynomial', 'a rational function', 'an exponential function', 'a quadratic function'], 'a rational function', placeholder => 'Select One'); + +BEGIN_PGML + +Consider the function [`f(x) = \displaystyle{[$f]}`]. + +What type of function is [`f`]? + +**Answer:** [`f`] is [_]{$popup}. +---- + +END_PGML + +Context("Interval"); + +$a = 0;$b = 0; + +if ($singularity1 < $singularity2) { + $a = $singularity1; $b = $singularity2; +} else { + $a = $singularity2; $b = $singularity1; +} + +$domain = Union("(-infinity, $a) U ($a, $b) U ($b, infinity)"); + +BEGIN_PGML + +What is the domain of [`f`]? Express your answer using interval notation. + +**Answer:** [`\text{dom}(f)=`] [_]{$domain} + +---- + +END_PGML + +$intercepts = MultiAnswer($xintercept1, $xintercept2)->with( + singleResult => 0, + checker => sub { + my ($correct, $student, $self) = @_; + my ($x1stu, $x2stu) = @{$student}; + my ($x1, $x2) = @{$correct}; + + if (($x1 == $x1stu && $x2 == $x2stu) || ($x1 == $x2stu && $x2 == $x1stu)) { + return [1,1]; + } elsif ($x1 == $x1stu || $x2 == $x1stu) { + return [1,0]; + } elsif ($x1 == $x2stu || $x2 == $x2stu) { + return [0,1]; + } else { + return [0,0]; + } + } +); + +BEGIN_PGML + +What are the [`x`]-intercepts of the graph of [`f`]? + +**Answer:** [`x =`] [_]{$intercepts} and [`x = `] [_]{$intercepts} + +---- +END_PGML + +Context("Fraction"); + +$yintercept = Fraction("$f_num_c/$f_den_c")->reduce; + +BEGIN_PGML + +What is the [`y`]-intercept of the graph of [`f`]? + +**Answer:** [`y =`] [_]{$yintercept} + +END_PGML + +ENDDOCUMENT(); \ No newline at end of file diff --git a/Contrib/TRU/math1070/maximizeQuadraticProfit.pg b/Contrib/TRU/math1070/maximizeQuadraticProfit.pg new file mode 100644 index 0000000000..5e2239d6dd --- /dev/null +++ b/Contrib/TRU/math1070/maximizeQuadraticProfit.pg @@ -0,0 +1,172 @@ +## DBsubject(Algebra) +## DBchapter(Quadratic equations and functions) +## DBsection(Applications and models) +## Level(3) +## KEYWORDS('demand', 'price', 'cost', 'revenue', 'profit', 'optimization', 'quadratic', 'break-even') +## Author(Kyle Schlitt) +## Institution(TRU) +## Language(en) + +DOCUMENT(); + +loadMacros( + "PGstandard.pl", + "PGML.pl", + "contextCurrency.pl", + "parserMultiAnswer.pl" +); + +Context()->variables->add(q => 'Real'); + +Context()->flags->set( + tolerance => 0.00001, + tolType => "absolute", +); + +Context()->noreduce('(-x)+y'); + +# optimal production level/price to maximize profit +$oq = random(500,1000,10); + +# break even quantities (ensure multiples of 10) +$radius = random(200,300,10); +$q1 = $oq - $radius; +$q2 = $oq + $radius; + +# generate profit function +$a = -1; $b = $q1 + $q2; $c = -($q1 * $q2); +$profit = Formula("$a q^2 + $b q + $c")->reduce; + +# maximum profit obtainable +$max_profit = $profit->substitute(q => "$oq")->eval(); + +# generate slope for demand equation +@slopes = (0.1, 0.2, 0.25, 0.5); +$m = -$slopes[random(0,3,1)]; + +# optimal price for tickets +$op = $b + $m * $oq; + +# demand equation intercept +$demand_intercept = $b; + +# demand function +$demand = Formula("$b + $m q")->reduce; +$max_q = $b/(-$m); +$domain = Interval("[0, $max_q]"); + +# revenue function +$revenue = Formula("$m q^2 + $b q"); + +# generate break-even prices +$p1 = $b + $m * $q1; +$p2 = $b + $m * $q2; + +# generate cost function +$fixed_cost = -$c; +$squared_coef = 1 + $m; +$cost = Formula("$fixed_cost + $squared_coef q^2"); + +# there are two break-even quantities which may be supplied in either order +$break_even_q = MultiAnswer($q1, $q2)->with( + singleResult => 0, + checker => sub { + my ($correct, $student, $self) = @_; + my ($q1stu, $q2stu) = @{$student}; + my ($Q1, $Q2) = @{$correct}; + + if (($Q1 == $q1stu && $Q2 == $q2stu) || ($Q1 == $q2stu && $Q2 == $q1stu)) { + return [1,1]; + } elsif ($Q1 == $q1stu || $Q2 == $q1stu) { + return [1,0]; + } elsif ($Q1 == $q2stu || $Q2 == $q2stu) { + return [0,1]; + } else { + return [0,0]; + } + } +); +BEGIN_PGML + +A music production company is planning to host an exclusive VIP concert, and they have asked for your help in deciding on the price of tickets. + +They predict that the demand equation for concert tickets is given by + +>>[`p = [$demand]`],<< + +where: + +* [`p`] is the price per ticket (in $), and +* [`q`] is the number of tickets sold. + +The cost of setting up the event and selling tickets (in $) is given by the function + +>>[`C(q) = [$cost]`].<< + +---- + +What are the cost, revenue, and profit functions, and what are their domains? + +**Answer:** + +[`C(q) = [$cost]`] with [`\text{dom}(C) = `] [_]{Interval("[0,infinity)")} + +[`R(q) = `] [_]{$revenue} with [`\text{dom}(R) = `] [_]{$domain} + +[`P(q) = `] [_]{$profit} with [`\text{dom}(P) = `] [_]{$domain} + +END_PGML + +BEGIN_PGML_HINT + +To find [`R(q)`], recall that the revenue function is given by [`R(q) = pq`]. Combine this with the demand equation! +END_PGML_HINT + +BEGIN_PGML + +---- + +How many tickets must be sold to break even? + +**Answer:** + +Either [_]{$break_even_q} or [_]{$break_even_q} tickets must be sold to break even. + +---- + +For what values of [`q`] will the company earn a profit, or at least not lose any money? Express your answer using interval notation. + +**Answer:** [_]{Interval("[$q1,$q2]")} + +---- + +How many tickets should be sold in order to maximize profit? + +**Answer:** The company should sell [_]{$oq} tickets to maximize profit. + +---- + +END_PGML + +Context("Currency"); + +BEGIN_PGML + +What will be the maximum profit? + +**Answer:** [_]{Currency($max_profit)} + +---- + +In order to achieve this maximum profit, what price should the company sell their tickets at? + +**Answer:** [_]{Currency($op)} + +END_PGML + +BEGIN_PGML_HINT + +Use the demand equation! +END_PGML_HINT + +ENDDOCUMENT(); diff --git a/Contrib/TRU/math1070/parabolaFeatures.pg b/Contrib/TRU/math1070/parabolaFeatures.pg new file mode 100644 index 0000000000..c7623b9ed6 --- /dev/null +++ b/Contrib/TRU/math1070/parabolaFeatures.pg @@ -0,0 +1,161 @@ +## DBsubject(Algebra) +## DBchapter(Quadratic equations and functions) +## DBsection(Graphs) +## Level(2) +## KEYWORDS('domain', 'range', 'quadratic', 'parabola', 'intercepts', 'axis of symmetry', 'vertex') +## Author(Kyle Schlitt) +## Institution(TRU) +## Language(en) + +DOCUMENT(); + +loadMacros( + "PGstandard.pl", + "PGML.pl", + "MathObjects.pl", + "contextArbitraryString.pl", + "parserPopUp.pl", + "parserImplicitEquation.pl", + "parserMultiAnswer.pl", + "parserFunction.pl" +); + +$x_intercept1 = random(2,7); +$x_intercept2_num = 1; +$x_intercept2_den = random(2,7); +$x_intercept2 = $x_intercept2_num/$x_intercept2_den; + +$a = $x_intercept2_den; +$b = -($x_intercept2_den*$x_intercept1 + $x_intercept2_num); +$c = $x_intercept1*$x_intercept2_num; + +if (random(0,1,1) == 0) { + $a = -$a;$b = -$b;$c = -$c; + $direction = "a downwards"; + $minmax = "maximum"; +} else { + $direction = "an upwards"; + $minmax = "minimum"; +} + +$popup1 = DropDown( + ['an upwards', 'a downwards'], + $direction, + placeholder => 'Select One' +); + +$popup2 = DropDown( + ['line', 'curve', 'sinusoidal wave', 'circle', 'hyperbola', 'parabola', 'ellipse'], + 'parabola', + placeholder => 'Select One' +); + +$popup3 = DropDown( + ['minimum', 'maximum'], + $minmax, + placeholder => 'Select One' +); + +Context()->noreduce('(-x)+y','y-x'); +$f = Formula("$a x^2 + $b x + $c")->reduce; + +BEGIN_PGML + +Define the function [`f`] by [`f(x) = [$f]`]. + +---- + +Describe the graph of [`f`]. + +**Answer:** The graph of [`f`] is [_]{$popup1} facing [_]{$popup2}. + +---- + +END_PGML + +Context("ImplicitEquation"); + +Context()->variables->set( + x => { limits => [-100,100] } +); + +$symmetry = -$b/(2*$a); + +$axis = ImplicitEquation("x = $symmetry"); + +BEGIN_PGML + +Find the axis of symmetry and express it as an equation. + +**Answer:** [_]{$axis} + +---- + +END_PGML + +Context("Point"); + +Context()->variables->are( x => 'Real'); +parserFunction('f(x)' => $f); + +$vertex_x = $symmetry; +$vertex_y = $f->substitute(x => "$symmetry")->eval(); +$vertex = Compute("($vertex_x,f($vertex_x))"); + +BEGIN_PGML + +Find the vertex of [`f`], and express it as a point. + +**Answer:** [_]{$vertex} + +---- + +END_PGML + +Context("Interval"); +Context()->variables->are( x => 'Real'); +parserFunction('f(x)' => $f); + +if ($a > 0) {$range = Interval("[$vertex_y,infinity)");} +else {$range = Interval("(-infinity, $vertex_y]");} + +BEGIN_PGML + +What is the range of [`f(x)`]? + +**Answer:** +[`\text{ran}(f)=`][_]{$range} + +---- + +END_PGML + +Context("Numeric"); + +$intercepts = MultiAnswer($x_intercept1, $x_intercept2)->with( + singleResult => 0, + checker => sub { + my ($correct, $student, $self) = @_; + my ($x1stu, $x2stu) = @{$student}; + my ($x1, $x2) = @{$correct}; + + if (($x1 == $x1stu && $x2 == $x2stu) || ($x1 == $x2stu && $x2 == $x1stu)) { + return [1,1]; + } elsif ($x1 == $x1stu || $x2 == $x1stu) { + return [1,0]; + } elsif ($x1 == $x2stu || $x2 == $x2stu) { + return [0,1]; + } else { + return [0,0]; + } + } +); + +BEGIN_PGML + +What are the [`x`]-intercepts of the graph of [`f`]? + +**Answer:** [`x = `] [_]{$intercepts} and [`x = `] [_]{$intercepts} + +END_PGML +ENDDOCUMENT(); \ No newline at end of file diff --git a/Contrib/TRU/math1070/shoeSalesman.pg b/Contrib/TRU/math1070/shoeSalesman.pg new file mode 100644 index 0000000000..b2b3b24447 --- /dev/null +++ b/Contrib/TRU/math1070/shoeSalesman.pg @@ -0,0 +1,120 @@ +## DBsubject(Algebra) +## DBchapter(Functions) +## DBsection(Interpretation and applications) +## Level(2) +## KEYWORDS('cost', 'revenue', 'profit', 'break-even') +## Author(Kyle Schlitt) +## Institution(TRU) +## Language(en) + +DOCUMENT(); + +loadMacros( + "PGstandard.pl", + "PGML.pl", + "contextCurrency.pl", +); + +Context("Currency"); +Context()->variables->add(q => "Real"); + +# parameters for entire question +$variable_cost_per_unit = 30 + random(0,10,1); +$selling_price_per_unit = 120 + random(0,80,10); +$profit_per_unit = $selling_price_per_unit - $variable_cost_per_unit; +$break_even_quantity = 80 + random(0,40,1); +$fixed_cost = $break_even_quantity * ($selling_price_per_unit - $variable_cost_per_unit); +$utils = 800 + random(0,100,10); +$rent = $fixed_cost - $utils; + +# parameters for specific parts of question +$target_cost = $fixed_cost + $variable_cost_per_unit * random(600,700,1); + +$cost_function = Formula("$fixed_cost + $variable_cost_per_unit q"); +$revenue_function = Formula("$selling_price_per_unit q"); +$profit_function = Formula("$profit_per_unit q - $fixed_cost"); + +BEGIN_PGML + +Bob runs a shoe-store at a large retail mall. Each month, he pays [`[@ Currency($rent) @]*`] in rent, with average electric bills in the amount of [`[@ Currency($utils) @]*`]. On average, his suppliers charge [`[@ Currency($variable_cost_per_unit) @]*`] for a pair of shoes, and he sells each pair to customers for [`[@ Currency($selling_price_per_unit) @]*`] dollars. Assume that Bob has no other costs to worry about. + +---- + +What are the fixed costs? + +**Answer:** [_]{Currency($fixed_cost)} per month. + +What is the variable cost per unit? + +**Answer:** [_]{Currency($variable_cost_per_unit)} per pair of shoes. + +END_PGML + +BEGIN_PGML_HINT + +Remember to include units! For example, three dollars should be expressed as [`\$3.00`]. +END_PGML_HINT + +BEGIN_PGML +---- + +Determine the Cost (C), Revenue (R), and Profit (P) functions, where [`q`] is the number of pairs of shoes that Bob orders and sells -- units are not required here. + +**Answers:** + +[`C(q)=\ `][_]{$cost_function} + +[`R(q)=\ `][_]{$revenue_function} + +[`P(q)=\ `][_]{$profit_function} + +---- + +END_PGML + +$num_shoes_part_a = 10 + random(0,10,1); +$answer_part_a = $cost_function->substitute(q=>"$num_shoes_part_a")->eval(); + +$answer_part_b = 400 + random(0,100,10); +$target_cost_part_b = $cost_function->substitute(q=>"$answer_part_b")->eval(); + +$num_shoes_part_c = 20 + random(0,10,1); +$answer_part_c = $revenue_function->substitute(q=>"$num_shoes_part_c")->eval(); + +$num_shoes_part_d = random(34,134,5); +$answer_part_d = $profit_function->substitute(q=>"$num_shoes_part_d")->eval(); + +$answer_part_e = random(147,447,6); +$target_profit_part_e = $profit_function->substitute(q=>"$answer_part_e")->eval(); + +BEGIN_PGML + +Help Bob answer the following questions. Be sure to include units for any monetary values. Note that profit will be negative if Bob's company loses money. + +What is the total cost for Bob to order [`[$num_shoes_part_a]`] pairs of shoes? + +**Answer:** [_]{Currency($answer_part_a)} + +Assuming Bob's Total costs are [`[@ Currency($target_cost_part_b) @]*`], how many pairs of shoes did he order? + +**Answer:** [_]{$answer_part_b} + +How much revenue does Bob generate from selling [`[$num_shoes_part_c]`] pairs of shoes? + +**Answer:** [_]{Currency($answer_part_c)} + +If Bob orders [`[$num_shoes_part_d]`] pairs of shoes from his supplier, what is his total profit from selling them all? + +**Answer:** [_]{Currency($answer_part_d)} + +What is Bob's break-even quantity for the month? + +**Answer:** [_]{$break_even_quantity} + +How many pairs of shoes must Bob sell each month to earn a monthly profit of [`[@ Currency($target_profit_part_e) @]*`]? + +**Answer:** [_]{$answer_part_e} + +END_PGML + +ENDDOCUMENT(); diff --git a/Contrib/TRU/math1070/taxiCompanies.pg b/Contrib/TRU/math1070/taxiCompanies.pg new file mode 100644 index 0000000000..5a51b0a2fb --- /dev/null +++ b/Contrib/TRU/math1070/taxiCompanies.pg @@ -0,0 +1,113 @@ +## DBsubject(Algebra) +## DBchapter(Linear equations and functions) +## DBsection(Applications and models) +## Level(2) +## KEYWORDS('cost', linear equations') +## Author(Kyle Schlitt) +## Institution(TRU) +## Language(en) + +DOCUMENT(); + +loadMacros( + "PGstandard.pl", + "PGML.pl", + "niceTables.pl", + "contextCurrency.pl", + "parserPopUp.pl" +); + +Context("Currency"); + +$x = random(20,30,1); +$km = int($x/random(2,5,1)); + +$base_B = 3 + 0.01*random(0,400,1); + +$mile_A = 0.15 + 0.01*random(0,25); +$mile_B = $mile_A; +while ($mile_B == $mile_A) {$mile_B = 0.15 + 0.01*random(0,25);} + +$base_A = $x*($mile_B - $mile_A) + $base_B; + +while ($base_A < 2) { + $x = $x - 1; + $base_A = $base_A - ($mile_B - $mile_A); +} + +$summary = DataTable( + [ + [ + ['', rowtop => '1pt', midrule => 1, tex => '\cellcolor[HTML]{000000}'], + ['Base Rate', tex => '\cellcolor[HTML]{FFFFFF}'], + ['Mileage Fee',tex => '\cellcolor[HTML]{FFFFFF}'] + ], + [ + ['Company A', tex => '\cellcolor[HTML]{FFFFFF}'], + [Currency("$base_A"),tex => '\cellcolor[HTML]{FFFFFF}'], + [Currency("$mile_A"), tex => '\cellcolor[HTML]{FFFFFF}'] + ], + [ + ['Company B', midrule => 1, tex => '\cellcolor[HTML]{FFFFFF}'], + [Currency("$base_B"), tex => '\cellcolor[HTML]{FFFFFF}'], + [Currency("$mile_B"), tex => '\cellcolor[HTML]{FFFFFF}'] + ] + ], align => '|r|c|c|' +); + +BEGIN_PGML + +You are stranded without a vehicle and need to call a taxi. There are two companies to choose from: Company A and Company B. + +Each of these companies charges a different base rate and mileage charge, both of which are shown in the table below. + +[$summary]* + +---- + +END_PGML + +$cost_func_A = Formula("$base_A + $mile_A x"); +$cost_func_B = Formula("$base_B + $mile_B x"); + +BEGIN_PGML + +Let [`x`] denote the length of your trip, measured in km. + +Express the cost of travelling with Company A as a function [`C_{A}`] of [`x`]. + +**Answer:** [`C_{A}(x)=`] [_]{$cost_func_A} + +Express the cost of travelling with Company B as a function [`C_{B}`] of [`x`]. + +**Answer:** [`C_{B}(x)=`] [_]{$cost_func_B} + +---- + +END_PGML + +$cost_A = $cost_func_A->substitute(x => "$km")->eval(); +$cost_B = $cost_func_B->substitute(x => "$km")->eval(); + +if ($cost_A < $cost_B) {$company_answer = "Company A";} +else {$company_answer = "Company B";} + +$popup = DropDown( + ['Company A', 'Company B'], + $company_answer, + placeholder => 'Select One' +); + +BEGIN_PGML + +If you need to travel [`[$km]`]km, which taxi company should you call? + +**Answer:** [_]{$popup} + +At what point would this change? That is, how far away would your destination need to be before you would change your mind? + +**Answer:** [_]{$x} km + +END_PGML + +ENDDOCUMENT(); \ No newline at end of file