0
$\begingroup$

I have two functions for the x variable. I want to extract x values that make the functions equal.

(1)

a + b - a b + c x - b c x + d x - a d x- a e x + a b e x- b f x + a b f x- c d x + a d e x + b c f x - a b e f x

(2)

a + b - a b + c x - b c x + d x - a d x - a e x + a b e x - b f x + 
 a b f x - c d x^2 + a d e x^2 + b c f x^2 - a b e f x^2

where $x\in[0,1]$ equal to each other (i.e. (1)=(2) )

Is it possible to make a program according to the structure of the functions in order to be equal according to the values of x?

A program that extracts x values in the form of a table that makes the functions equal. where $x\in[0,1]$

I need a program that prints 20 $x_i$ values in the form of a table with equal functions

variables = exp // Variables // Sort;

    exp = -Subscript[x, 3] Subscript[x, 4] Subscript[x, 5] Subscript[x, 6]
   Subscript[x, 7] + 
 Subscript[x, 1] Subscript[x, 3] Subscript[x, 4] Subscript[x, 5]
   Subscript[x, 6] Subscript[x, 7] + 
 Subscript[x, 2] Subscript[x, 3] Subscript[x, 4] Subscript[x, 5]
   Subscript[x, 6] Subscript[x, 7] - 
 Subscript[x, 1] Subscript[x, 2] Subscript[x, 3] Subscript[x, 4]
   Subscript[x, 5] Subscript[x, 6] Subscript[x, 7];

exper = -\!\(\*SubsuperscriptBox[\(x\), \(3\), \(2\)]\) Subscript[x, 4]
   Subscript[x, 5] Subscript[x, 6] Subscript[x, 7] + Subscript[x, 1] 
\!\(\*SubsuperscriptBox[\(x\), \(3\), \(2\)]\) Subscript[x, 4]
   Subscript[x, 5] Subscript[x, 6] Subscript[x, 7] + Subscript[x, 2] 
\!\(\*SubsuperscriptBox[\(x\), \(3\), \(2\)]\) Subscript[x, 4]
   Subscript[x, 5] Subscript[x, 6] Subscript[x, 7] - 
 Subscript[x, 1] Subscript[x, 2] 
\!\(\*SubsuperscriptBox[\(x\), \(3\), \(2\)]\) Subscript[x, 4]
   Subscript[x, 5] Subscript[x, 6] Subscript[x, 7]

;

 Module[{expValue, experValue, varValues}, 
     With[{nbrOfResults = 20}, 
        Table[Catch[
           Do[If[0.8 <= (expValue = 
                Round[exp /. 
                  Thread[variables -> (varValues = 
                      Round[RandomReal[{0, 1}, Length[variables]], .1])], 
                 0.01]) < 1, 
             Throw[{NumberForm[#, {3, 1}] & /@ varValues, 
                NumberForm[expValue, {4, 5}], 
                NumberForm[
                 exper /. Thread[variables -> varValues], {4, 5}]} // 
               Flatten]], 10000]], {nbrOfResults}] // 
         SortBy[#, #[[-2]] &] &] // 
       Prepend[#, {variables, "exp", "exper"} // Flatten] & // 
      Grid[#, Frame -> All] &]

This program prints values of functions if they are larger than 0.5

I want to print values of variables if the functions are equal

$\endgroup$
1
  • $\begingroup$ Have a look at Solve and NSolve. $\endgroup$ – Henrik Schumacher Jul 31 '17 at 8:52
1
$\begingroup$

Your particular equations factorize:

eqn1 = a + b - a b + c x - b c x + d x - a d x - a e x + a b e x - 
   b f x + a b f x - c d x + a d e x + b c f x - a b e f x ;

eqn2 = a + b - a b + c x - b c x + d x - a d x - a e x + a b e x - 
   b f x + a b f x - c d x^2 + a d e x^2 + b c f x^2 - a b e f x^2;

Solve[eqn1 == eqn2, x]

(* {{x -> 0}, {x -> 1}} *)

So either $x=0$ or $x=1$ (for all parameter values). The equations actually factorize, so you can see that these are the only solutions.

Simplify[eqn1 - eqn2]

(* (c - a e) (d - b f) (-1 + x) x == 0 *)
$\endgroup$
1
  • $\begingroup$ I need a program that prints 100 X values in the form of a table with equal functions $\endgroup$ – Emad kareem Jul 31 '17 at 8:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.