Formulas: Using Conditional Operations To Prevent Certain Numbers

Formulas: Using Conditional Operations To Prevent Certain Numbers

by Dipo Adeniyi -
Number of replies: 2
Good evening,

Please I am trying to achieve this:
Question
Subtract Mixed Numbers with Formulas using the "IF Conditional statement" to prevent same selection of both denominators.
The ideal question should like this (if the condition works):

Question 
Variables used are:
wn1 = first whole number = 8, tn1 = first numerator = 2, bn1 = first denominator = 4, wn2 = second whole number = 5, tn2 = second numerator = 3 and bn2 = second denominator = 5.

Random Variable: wn1= {3,4,5, 6}; k = {32:46:2}; wnk = {1, -1, 2, -2}; tn1 = {1, 2};  tn2  = {1, 2, 3}; bnk = {1, 2}

Global Variable: bn1 = tn1 + 1;

bn2 = tn2 + bnk; 

bn2 = (bn2=bn1) ? (bn2+1) : bn2;  #(Prevent denominators to be the same)

bn1 = (bn1=bn2) ? (bn1+1) : bn1;   #(Prevent denominators to be the same)

tn2 = (tn1/bn1=tn2/bn2) ? (tn2+1) : tn2; #(This is to prevent fractional parts to be the same, else answer will be whole number) 

wn2 = wn1 + wnk;  wn1 = (wn1 <= wn2+2)  ?  (wn1+4) : wn1; #(This is to prevent first whole number to be always greater than the second whole number, so that there is no negative answer. This works!)

im1 = (wn1*bn1)+tn1; im2 = (wn2*bn2)+tn2; #step1. change all to improper fractions

cm = lcm(bn1, bn2); # find lcm of both denominators

cf1= (cm/bn1)*im1; cf2= (cm/bn2)*im2; # combining fraction step 1;

imfa=(cm/bn1)*im1 - (cm/bn2)*im2;

wa = floor(imfa/cm); ta = imfa-(cm*wa); cf=gcd(ta,cm); ta = ta/cf; ba = cm/cf


However, I still get mixed numbers like the below, this not giving accurate result:
Mixed Numbers

I also  attach the XML file.

Any help would be greatly appreciated.

Thanks.

Dipo.


 
Average of ratings: -
In reply to Dipo Adeniyi

Re: Formulas: Using Conditional Operations To Prevent Certain Numbers

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

This seemingly very simple problem is in fact a bit tricky.

The requirements for the given data set are:

  • two mixed numbers with
    • different whole parts
    • different fraction parts
  • fraction parts are simplified, e.g. 1/2 not 2/4,
  • fraction parts have a different denominator
  • final answer is positive

Although in general one would like to satisfy these requirements analytically, it is not that easy. I suggest instead that the fraction parts be selected. It's not as elegant, but it's easier.

Simplified fractions with denominators ranging from 2 to 9 are

1/2,
1/3, 2/3,
1/4, 3/4,
1/5, 2/5, 3/5, 4/5,
1/6, 5/6,
1/7, 2/7, 3/7, 4/7, 5/7 6/7,
1/8, 3/8, 5/8, 7/8,
1/9, 2/9, 4/9, 5/9, 7/9, 8/9

where the fractions form 8 groups (the 8 lines) according to the value of their denominator. The pattern is not regular hence the difficulty in generating it analytically. However, by grouping the fractions in this way, it becomes easy to choose the first fraction part in one group and the second fraction part in another group, which satisfies the requirements for the given data set.

The rest is just standard simplification of a mathematical expression.

Just for fun. By proceeding in this way, the resulting fraction can never be reduced to an integer. It is always simplified, as well as the fraction part of the corresponding mixed number. Is it true? Can you demonstrate it?

I'm not sure of the math, but given that the first integer part can take 9 different values for each value of the second integer part, that the second integer part can also take 9 different values, that the first fraction part can take 27 different values, and the second fraction part can take 27-1 different values, the number of possible different given data sets is 9 x 9 x 27 x 26 = 56862, which is probably sufficient in a normal context.

MoodleForum_20230521_1944.png

You can try this question at: https://dynamiccourseware.org/course/view.php?id=78&section=82➚.

Average of ratings: Useful (1)
In reply to Dominique Bauer

Re: Formulas: Using Conditional Operations To Prevent Certain Numbers

by Dipo Adeniyi -
Thank you so much. I deeply appreciate.