I know how to solve a problem in Maple, but can't translate into Maple TA. I'm teaching elementary statistics, and want students to estimate a median using a cumulative frequency distribution.
In Maple, I randomly generate some intervals and frequencies. Then I define the CFD by giving the end points and the cumulative frequency, like;
(1) XY:= Array([[x0,cf0],[x1,cf1],[x2,cf2],[x3,cf3],[x4,cf4]]);
Then I use the endpoints to define a spline (the ogive or CFD). Then I invert it, and find the value of x that is equal to the y4/2:
(2) solve(CurveFitting[Spline](XY, x, degree=1)=(cf4)/2,x);
So, now I want to write a Maple TA question that gives the student random frequencies and asks them to estimate the median from the CFD. How do I write an algorithm to generate (2) as an answer? I've tried:
(3) $med=maple("map(x->solve(CurveFitting[Spline]($XY, y, degree=1)=x,y),$cf5/2)");
but I just get a message saying: Warning, solutions may have been lost
I'm using Maple TA 3.01 and therefore I've written the above in Maple 11.
Thanks in advance,
Stephen
why use map?
Stephen,
Why do you need the extra map? Have you tried using:
$med=maple("solve(CurveFitting[Spline]($XY, x, degree=1)=$cf5/2,x)");But, I believe the real problem is that some of the data in XY, or cf5, is not numeric. I get the solutions may be lost message if I call solve with symbolic values in XY.
Also, I notice that your XY ends with cf4 but you later refer to cf5. If all data is numeric, then I have no trouble.
Good luck
Doug
another issue
Doug is probably right, something is not numeric.
But another observation is your use of an arrow.
If I set up a function in MapleTA by the construction
$f=maple("x->x^2");
then MapleTA throws errors. I find I need to use
$f=maple("proc(x) x^2 end");
or
$f=maple("unapply(x^2,x)");
How to invert a (spline) function in Maple?
Thanks for the help. I changed to defining numeric values first, and cleaned my formulas up as suggested, and now it works the same in Maple and Maple TA. However, it doesn't work properly. An example:
A:=Array([[2.5,0],[4.5,3],[6.5,12],[8.5,25],[10.5,40],[12.5,47]]);
These (x,y) pairs are monotonically increasing.
evalf(solve(CurveFitting[Spline](A, x, degree = 1) = (47/2),x));
This finds the point on the spline connecting the points that marks the median. Maple gives two answers, however:
8.269230769, 8.300000000
When I check with my calculator, the first number gives 23.5 when substituted, but the second gives 23.7. When I perform a similar to find the first quartile (solve...=47/4,x) Maple (and Maple TA) gives three answers, the right one and two others.
If I plot the spline it is monotonically increasing, so the inverse shold be well defined. What don't I understand?
Thanks in advance.
Stephen
The problem with multiple answers
I should add that the biggest problem is that Maple TA grades the right answer as wrong. I'm not sure how it obtains the other answer, so I'm not sure it that would be marked correct, or if it is expecting two answers. I probably would not have really looked at it if it accepted either answer. I'm not sure how likely it is that a student would stumble across Maple's "wrong" answer, so I don't know how big a problem that would be.
On a somewhat related note, if I feed it a sample of numbers with more than one mode, Maple's Mode function only reports the smallest one, and Maple TA will only accept that as the right answer. In that case I would like it to accept all of them as the only answer worth 100%.
TIA
Stephen
Multiple answers
Stephen,
It would easier to help if you would simply post the .qu script.
Probably you need to finnesse with sets.
For a toy example, suppose the answer to a MapleTA problem is
$ans=maple("{solve(x^2-1=0,x)}");
Notice I wrapped -1,1 into a set {-1,1}.
Imagine you think the student will only stumble upon one of the two solutions. Then your grading algorithm should be something like
evalb($RESPONSE in $ans);
Multiple answers
Whatever it is I don't understand, it is in Maple, since that gives the two answers. I'm inverting this function, so the answer should be unique:
The qu file is Download 7361_estimation.zip
View file details.
Thanks for the help
Stephen
(another) solve bug
This looks like a bug in Maple 10 and Maple 11. In Maple 9.5
A:=Array([[2.5,0],[4.5,3],[6.5,12],[8.5,25],[10.5,40],[12.5,47]]);
solve(CurveFitting[Spline](A, x, degree = 1) = (47/2),x);
returns only one number... the correct answer.
Maple 10 and 11 bomb. You should report the bug.
As a workaround, maybe use fsolve instead of solve.
PS..nice MapleTA question! You must have worked hard on it.
fsolve works!
fsolve does work. Thanks a lot; I reported the bug. I removed older versions of Maple and never thought to try them.
Thanks, I did spend a lot of time on it, so I was frustrated at it not working. It's a relief to be able to put it away.
Stephen