I have a question about whether Doenet can generate random functions from a list of functions in a “setup”. I am asking because I would like students to practice decomposing functions before using the Chain Rule. Instead of creating 10 practice problems, could I create one problem for students to enter two solutions (inner function and outer function) and have a button to generate a new function for them to practice?
For Example, let’s say I would like to generate f(g(x)) from a preset list of functions from a list.
\sqrt{x}
\dfrac{1}{x}
\cos x
\sin x
\vert x\vert
b^x
ax^2
\sqrt[3]{x}
x^3
My thought is that I would need to name each function, then build each function, each with math the math tag and create f(g(x)) with its own name.
I am attaching a worksheet that I have created. Any help is appreciated.
Check this example. If it does what you are looking for, you can modify it to your liking. I threw in some constants too.
<setup>
<selectFromSequence name="const" from="2" to="10" numToSelect="5"></selectFromSequence>
<selectFromSequence name="power" from="2" to="10" numToSelect="3" exclude="$const"></selectFromSequence>
<function name="linear">$const[1] x + $const[2]</function>
<function name="quadratic">$const[2] x^2 + $const[3] x + $const[4]</function>
<function name="exponential">$const[5]^($power[1] x)</function>
<function name="radical">sqrt($const[2] x^$power[2] +$const[4] x^$power[3])</function>
</setup>
<p>This selects two functions from a list of functions: <select name="selectedFunction" numToSelect="2">$linear $quadratic $exponential $radical</select></p>
<p>Now you can compute compositions: <m>f(g(x))=<math name="studentFacingQuestion" simplify="normalizeOrder">$$selectedFunction[1]($selectedFunction[2])</math></m> </p>
<p><m>g(x)=</m><mathInput name="userG" prefill="$selectedFunction[2]"></mathInput></p>
<p><m>f(x)=</m><mathInput name="userF" prefill="$selectedFunction[1]"></mathInput></p>
<answer>
<award>
<when>$$userF($userG)=$studentFacingQuestion</when>
</award>
</answer>
@Duane_Nykamp1, normalizeOrder does not seem to be affecting the order of terms coming from function compositions. As you flip through the variants, you’ll notice some that are not in the expected order.
That’s because attributes like simplify or expand given to a function apply after function evaluation, not to the formula used in their definition. If you want to apply such transformations to the formula, you need to give the function a <math> child with the appropriate attributes.
This is definitely confusing, so maybe it was a bad design decision. It’s hard to illustrate rationale for the different options with simplify="normalizedOrder", but here is an example of showing the difference between putting expand in the function versus in a math definition the formula.
But, this distinction is definitely confusing. Maybe there is a way to apply the attributes of the <function> to the formula if there isn’t an explicit <math> child.
Thank you for the response, but I am having trouble understanding what you mean. I am having trouble understanding how to establish the relationship between the button and the functions. When you say “List of functions,” do I need to create my own equations in their general form? I tried to rename the list of functions that Anurag created, but I still get nothing. Here is the code:
I essentially switched the names and ended with the same result (nothing happened). I am sorry to be difficult, and I wish I could understand. I am continuing to look at the help document as well.
One reason you get nothing is that your select is called myFunctions (plural), but you are referencing it with $myFunction[1] (singular).
I also recommend putting the <select> in the <setup> rather than using hide. Otherwise, a direct reference like $myFunction[1] should also be hidden. (It does not seem to be hidden now, but that’s a bug…)
With the current setup of Doenet, it’s not easy to get new random selections of values. A <select> is designed to pick values once and for all (for each variant). We cannot reselect them. (It appears that we need a <sample> tag in Doenet, which would be the version of that where you can resample.)
Any solution I can think of to mimic such random sampling ends up being quite complicated. What is your use case for this? Would it suffice to just have this New Sample button be generated by the Assignment feature? In that case, your students would get a New Attempt button that would select a new variant, clear their responses, and give them a new attempt. You can see what variants are available to students by going through the options in the variant selector.
If that doesn’t work, then another option is to wait until we implement the ability for Doenet to manage its own variants. Then, you’d be able to have Doenet create this New Attempt button even apart from an Assignment.
If none of that works, we could try to come up with DoenetML that does this for you, but it might end up being overly complicated.