Integer to float conversion - prevention



  • Is there some way to prevent Mobius from changing all numbers to floats? I know I can make them strings like $function=x^"2"-"1"; but then if I wish to do something with $function even as simple as $secondfunction=$function; the integers get clobbered anyway and I get $secondfunction being x^2.0-1.0. I find this an annoying issue since when you typeset using mathml() you get a power of 2.0. There are even some weird problems with comparing the integer version to a float version in some cases in the $answer-$response comparison. However my immediate task is that I am trying to pick from a list of different functions and while I can think of a couple of ways to get around this, the best solution would be if Mobius left integers as integers so I am hoping there is some way to do that. 

    Any help (or changes to Mobius) will be greatly appreciated.

    thanks

    Andrew



  • Hi Andrew,

    There are a few possibilities, depending on what you are trying to do. As you mentioned writing this:

    $f='x^2-1';

    using either single or double quotes, will do it in that particular variable.

    On the other hand you did mention $ANSWER - $RESPONSE which suggests you are using a Maple-graded response area. In that case, relying on the Maple computation engine for the algorithm code may also be a solution.

    $f=maple("x^2-1");






  • I would suggest something to the effect of the following:  here is a .zip of the question above that can be imported:  https://naitca-my.sharepoint.c...
    ALGORITHM BELOW

    ------------------------------------------------------------------

    $degreeF=range(2,5,1);
    $degreeG=range(2,5,1);

    $randomMark=rint(100000);
    $callout=maple("
    with(RandomTools):
    randomize($randomMark):
    functionF:=Generate(polynom(nonzeroint(range=-10..10),x,degree=$degreeF)):
    functionG:=Generate(polynom(nonzeroint(range=-10..10),x,degree=$degreeG)):
    answer:=functionF+functionG:
    generateStrings:=seq(convert([functionF,functionG,answer][i],string),i=1..3):
    generateLatex:=seq(latex([functionF,functionG,answer][i],output=string),i=1..3):
    [generateStrings,generateLatex];
    ");
    $functionF=switch(0,$callout);
    $functionG=switch(1,$callout);
    $functionAnswer=switch(2,$callout);
    $functionFlatex=switch(3,$callout);
    $functionGlatex=switch(4,$callout);
    $functionAnswerLatex=switch(5,$callout);

    ---------------------------------------------------------------------------------------

    Essentially this will allow you to generate random functions, and automatically convert the function to latex that can be put directly into the question.  This avoids having to use the equation editor.



  • @chrisb thank you. I will see how that works. :)



  • @mschneider  thank you. . I did use Maple to generate MML but had not thought of doing Latex. That might be cleaner.  Much appreciated.


Log in to reply