Loren on the Art of MATLAB

Turn ideas into MATLAB

Mathematical Word Problems – Construction Tool 5

Posted by Loren Shure,

Do your kids have to practice solving mathematical word problems? Maybe they need to practice more during school breaks? I've written a function that can turn you in to a machine for torturing your kids with some.

Actually, this started off as a tool to find the date on which I was X times older than a colleague. It's super simple to do this with the help of the datetime datatype in MATLAB.


How does it work?

Given the birthdates for the elder and younger person, we want to return the date on which the elder is N times older than the younger one. Let's try it.

elderdate = datetime(1950, 1, 1);
youngerdate = datetime(1992, 7, 17);
doubledate = ntupleday(2, elderdate, youngerdate)

From there, it's just a matter of creating the relationships between various people, basically a set of linear constraints, and you are ready to embellish the stories as a new torture device for your kids. problems with for your kids to solve.


It was super easy to vectorize this, with respect to dates.

dd = datetime(1950, 1, 1:3:28)';
yd = datetime(1992, 7, 17:3:44)';
nd = ntupleday(2,dd,yd)
nd = 
  10×1 datetime array

Or for the multipliers

multiplier = 1.5:0.5:4.5;
newdates = ntupleday(multiplier, elderdate, youngerdate);
ans = 
  7×1 datetime array

What's the trend?

plot(newdates,multiplier, "-*")
ylabel("Age Multiplier")

Clearly, we can't expect the younger person to actually catch up in age to the older one - just likely that the difference gets less significant over time.

And Then I Realized...

I then realized there was nothing so special with dates except the format. So this can also be used for entities with other units, if you need to work that in.

Improvements to Be Made

It would be great to add the full functionality for building the problems. I leave that as an exercise for you. E.g., what functions should I add if I want to be able to construct a problem given one date, say the elder, and have it spit out what the birthdate would if the child was 3 years and 2 months younger than half dad's birthdate.


Do you take advantage of datetime in MATLAB? Especially if you have something novel you are doing with it, please share your thoughts here.

The Function ntupleday

function ndate = ntupleday(n, bdelder, bdyounger)
% The date on which the elder is n times as old as the younger
% NTUPLEDAY returns the date when the OLDER person is N times the age of
% the YOUNGER one.  Using this, parents can torture their children by
% making up a suite of word problems for the kids to solve.
% Example:
%   bdelder = datetime(1955,11,19);
%   bdyounger = datetime(1987,3,29);
%   doubleDate = ntupleday(2,bdelder, bdyounger)
ndate = bdyounger + (bdyounger-bdelder)./(n-1);
% Set the format of the output date to be the same as the first input date.
% If the input is of type "datetime".  Otherwise, don't worry about the
% format.
if isa(bdelder, "datetime")
   % ndate.Format = 'dd-MMM-uuuu';
   ndate.Format = bdelder.Format;
end %ntupleday
doubledate = 

Get the MATLAB code

Published with MATLAB® R2019a

5 CommentsOldest to Newest

Sorry for the misleading title. I was thinking of double, triple, quadruple and somehow ended up on ntuple - which is not really right! --loren
It seems you are supported by the etymology of n-tuple, at least according to Wikipedia. From that page:
The term originated as an abstraction of the sequence: single, double, triple, quadruple, quintuple, sextuple, septuple, octuple, ..., n‑tuple, ..., where the prefixes are taken from the Latin names of the numerals.
Bob Alvarez replied on : 4 of 5
Loren, I think you are on to important stuff. See this interesting post by David Wiley who is one of the leaders of the open educational resources (OER) movement. He thinks the internet can impact education as much as the printing press but is not being used anywhere near its potential. The first part of the article is a fascinating discussion of how the teachers resisted using the cheap books made available by the printing press in the 1400's. The second part, which is relevant to your post, discusses how the OER movement is resisting interactive learning opportunities made possible by the internet. I think Matlab is a great environment for producing interactive educational content not only about math, although that is obviously important, but other fields with its graphics capabilities and ability to develop applications rapidly. --Bob see the Aug. 13, 2019 post https://opencontent.org/blog/
@Bob- Thanks for passing along that blog link. Very interesting! I had heard about the books and content merely mimicking the calligraphic scribe work initially, and for quite a long time, but I hadn't fully drawn the analogy forward to teaching with the interactivity now available (though I am and have been a great believer in that for some time). Fascinating! --loren

Add A Comment

Your email address will not be published. Required fields are marked *

Preview: hide