Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 其它 > 资料存档 > MATLAB技术文章
MATLAB技术文章 MATLAB Technical Articles From Mathworks
回复
 
主题工具 显示模式
旧 2019-11-23, 20:41   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
默认 Mathematical Word Problems – Construction Tool

Mathematical Word Problems – Construction Tool 5

Posted by Loren Shure, July 30, 2019

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.

Contents
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.

Vectorizing

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 31-Jan-2035 03-Feb-2035 06-Feb-2035 09-Feb-2035 12-Feb-2035 15-Feb-2035 18-Feb-2035 21-Feb-2035 24-Feb-2035 27-Feb-2035Or for the multipliers

multiplier = 1.5:0.5:4.5;newdates = ntupleday(multiplier, elderdate, youngerdate);newdates'ans = 7×1 datetime array 16-Aug-2077 31-Jan-2035 25-Nov-2020 24-Oct-2013 23-Jul-2009 21-Sep-2006 11-Sep-2004What's the trend?

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



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.

Seriously...

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)ndate = bdyounger + (bdyounger-bdelder)./(n-1);if isa(bdelder, "datetime") ndate.Format = bdelder.Format;endend doubledate = datetime 31-Jan-2035
Get the MATLAB code

Published with MATLAB® R2019a


更多...
poster 当前离线   回复时引用此帖
回复

主题工具
显示模式

发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛启用 表情符号
论坛启用 [IMG] 代码
论坛启用 HTML 代码



所有时间均为北京时间。现在的时间是 23:44


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.