I tried to expand this expression (x-2)(x-3)
. I only want to recieive this result
(x-2)(x-3) = x^2 - 2x - 3x + 6
, not this result 6 - 5 x + x^2
when I use Expand
.
Expand[(x - 2) (x - 3)]
6 - 5 x + x^2
If you just want this for formatting output, you can use Latex
myExpand[(x-2) (x-3)]
myExpand[(x^2-2x+9) (x^2-3)]
Because this uses Latex strings to build the result, it does not ofcourse simplify same power terms of $x$ as Expand does.
<<MaTeX`
myExpand[p_Times]:=Module[{s,z,n,m,p1,p2},
p1=First@p; p2=Last@p;
s="";
Do[
z=p1[[n]]*p2[[m]];
s=s<>If[Internal`SyntacticNegativeQ[z],
ToString[TeXForm@z]
,
If[s=="",ToString[TeXForm@z],"+"<>ToString[TeXForm@z]]
]
,{n,1,Length@p1},{m,1,Length@p2}
];
MaTeX[s,Magnification->2]
]
You might also be interested in How can I get scheme product of two polynomials like this?
MaTeX
package installed? You need that ofcourse to work. The first command is <<MaTeX
which loads the package. This is well known package and very useful to have. Here is screen shot from my computer. !Mathematica graphics
$\endgroup$
s
you see in the function is Latex, but you need MaTeX to compile it. Just go to MaTeXInstall and run the command shown there. That is all.
$\endgroup$
s
and use it in your Latex document as is. Change the function above to return s
instead of calling MaTeX as I showed.
$\endgroup$
Distribute[(x - 2) . (x - 3)]
$\endgroup$