1
$\begingroup$

I'm new to Mathematica and trying to learn it on my own from various internet resources. I have the following question. How do I simplify the expression $$X=\frac{-b\pm\sqrt{b^2-4ac}}{2a}\tag{1}$$ where $a,b,c$ are real, known expressions in terms of other parameters (say, $x,y,z$). Again $x,y,z$ are in turn real, known functions of yet another set of real parameters (say, $p,q,r$).

How do I simplify the algebraic expression $X=\frac{-b\pm\sqrt{b^2-4ac}}{2a}$ to obtain $X$ in terms of $p,q,r$. Thank you.

An example For an example, consider $a=-x+y+z, b=x-y+z, c=x+y-z$. Then $x=p^2+q^2$, $y=q^2+r^2$ and $z=p^2+r^2$.

$\endgroup$
7
  • $\begingroup$ You can try the Simplify or the FullSimplify commands? It is better to make a MWE to illustrate the issue. $\endgroup$
    – Nasser
    Commented Sep 5, 2017 at 11:16
  • $\begingroup$ @Nasser Thanks. But after writing (1) how does one give the inputs i.e., $a=a(x,y,z)$, $b(x,y,z)$, $c(x,y,z)$, and in the next step $x(p,q,r), y(p,q,r), z(p,q,r)$, in order for the mathematica to evaluate $x$ as a function of $p,q,r$ i.e., $x(p,q,r)$? $\endgroup$
    – SRS
    Commented Sep 5, 2017 at 11:20
  • $\begingroup$ Something like Simplify[expr /. {a -> a[x, y, z], b -> b[x, y, z], c -> c[x, y, z]}] (and analogously for p, q, r) ought to work. We can't give more helpful feedback unless you show your actual expressions. $\endgroup$ Commented Sep 5, 2017 at 11:27
  • $\begingroup$ @J.M. I have given an example of what I have in mind. Does that help? $\endgroup$
    – SRS
    Commented Sep 5, 2017 at 11:30
  • $\begingroup$ Then, have you tried the operation I suggested? $\endgroup$ Commented Sep 5, 2017 at 11:31

2 Answers 2

2
$\begingroup$

Your question is answered by the Applying Transformation Rules tutorial and the ReplaceAll documentation page.

For example,

a + b /. {a -> x + y, b -> x + x^2}
(* 2 x + x^2 + y *)

a + b /. {a -> x + y, b -> x + x^2} /. {x -> p - q, y -> p + q}
(* p + 2 (p - q) + (p - q)^2 + q *)

Expand[%]
(* 3 p + p^2 - q - 2 p q + q^2 *)
$\endgroup$
1
  • $\begingroup$ This is really helpful. If it works out I'll accept the answer. @Szabolcs $\endgroup$
    – SRS
    Commented Sep 5, 2017 at 11:43
1
$\begingroup$

Define your expressions

a[x_, y_, z_]:=−x+y+z
b[x_, y_, z_]:=x−y+z
c[x_, y_, z_]:=x+y−z

then

x[p_, q_, r_]:=p^2+q^2
y[p_, q_, r_]:=q^2+r^2
z[p_, q_, r_]:=p^2+r^2

and finally substitute in your original expresson like so:

-b[x[p,q,r],y[p,q,r],z[p,q,r]]...
$\endgroup$
2
  • $\begingroup$ Sorry I didn't quite understand the last line. I'm trying to compute $X$ using the expression (1). @user42582 $\endgroup$
    – SRS
    Commented Sep 5, 2017 at 11:39
  • $\begingroup$ after having evaluated the definitions for a[x_,y_,z_], b[x_,y_,z_], c[x_,y_,z_],x[p_,q_,r_],y[p_,q_,r_],z[p_,q_,r_] you should use these newly defined functions in place of $a,b,c$ in your relation (1) eg replace the value of $b$ with b[x[p,q,r],y[p,q,r],z[p,q,r]] etc. (Perhaps you should also look at the solution by @Szabolcs above-it depends on a central theme in Mathematica :rules and replacing parts of expressions.) $\endgroup$
    – user42582
    Commented Sep 5, 2017 at 11:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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