Skip to content

Commit

Permalink
Remove roots from derivative exercises
Browse files Browse the repository at this point in the history
  • Loading branch information
HildoBijl committed Mar 18, 2024
1 parent 1d1cb6b commit 34f3f50
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ addSetupFromSteps(metaData)

function generateState() {
const x = selectRandomly(variableSet)
const [f, g1, g2] = getRandomElementaryFunctions(3, false, false, false).map(func => func.substitute('x', x))
const [f, g1, g2] = getRandomElementaryFunctions(3, false, false, false, false).map(func => func.substitute('x', x))
const c = getRandomInteger(-12, 12, [0])
return { f, c, g1, g2 }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ addSetupFromSteps(metaData)

function generateState() {
const x = selectRandomly(variableSet)
const [fRaw, g] = getRandomElementaryFunctions(2, false, false, false).map(func => func.substitute('x', x))
const [fRaw, g] = getRandomElementaryFunctions(2, false, false, false, false).map(func => func.substitute('x', x))
const c = getRandomInteger(-12, 12, [0])
const f = fRaw.multiply(c, true).basicClean()
return { f, g }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ addSetupFromSteps(metaData)

function generateState() {
const x = selectRandomly(variableSet)
const [f, g1, g2] = getRandomElementaryFunctions(3, false).map(func => func.substitute('x', x))
const [f, g1, g2] = getRandomElementaryFunctions(3, false, false, true, false).map(func => func.substitute('x', x))
const c = getRandomInteger(-12, 12, [0])
return { f, c, g1, g2 }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ addSetupFromSteps(metaData)

function generateState() {
const x = selectRandomly(variableSet)
const [fRaw, g] = getRandomElementaryFunctions(2, false).map(func => func.substitute('x', x))
const [fRaw, g] = getRandomElementaryFunctions(2, false, false, true, false).map(func => func.substitute('x', x))
const c = getRandomInteger(-12, 12, [0])
const f = fRaw.multiply(c, true).basicClean()
return { f, g }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ addSetupFromSteps(metaData)

function generateState() {
const x = selectRandomly(variableSet)
const [f1, f2] = getRandomElementaryFunctions(2, false, false).map(func => func.substitute('x', x))
const [g] = getRandomElementaryFunctions(1, false, false).map(func => func.substitute('x', x))
const [f1, f2, g] = getRandomElementaryFunctions(3, false, false, true, false).map(func => func.substitute('x', x))
const c = getRandomInteger(-12, 12, [0])
return { c, f1, f2, g }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ addSetupFromSteps(metaData)

function generateState() {
const x = selectRandomly(variableSet)
const [fRaw, g] = getRandomElementaryFunctions(2, false, false).map(func => func.substitute('x', x))
const [fRaw, g] = getRandomElementaryFunctions(2, false, false, true, false).map(func => func.substitute('x', x))
const c = getRandomInteger(-12, 12, [0])
const f = fRaw.multiply(c, true).basicClean()
return { f, g }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
const { getRandomInteger, selectRandomly, getRandomIndices } = require('../../../../util')
const { asExpression, Integer, Fraction } = require('../../../../CAS')

function getRandomElementaryFunctions(num = 1, includeConstant = false, includeDivision = true, includeX = true) {
function getRandomElementaryFunctions(num = 1, includeConstant = false, includeDivision = true, includeX = true, includeRoots = true) {
// Determine the indices of the elementary functions that we use.
const weights = [3, 9, 5, 3, 1, 2, 2, 2, 1, 2, 1]
if (!includeConstant)
weights[0] = 0
if (!includeDivision)
weights[2] = 0
if (!includeRoots) {
weights[3] = 0
weights[4] = 0
}
const indices = getRandomIndices(weights.length, num, true, weights)

// Set up the respective elementary functions.
Expand Down

0 comments on commit 34f3f50

Please sign in to comment.