How can I order the factors when using the sym and latex functions?
Mostra commenti meno recenti
Hi,
is it possible to control the order of the factors when using the sym and latex-functions?
E.g.
str = (5/8)*x;
out = latex(sym(str));
% produces out='\frac{5\, x}{8}'
% corresponding to (5*x)/8 and not (5/8)*x (='\frac{5}{8}x') as desired
I know these are mathematically identical, but I use the output for educating students and for them the second expression is easier to understand. I have thousands of expressions so need to find a way to do this automatically.
Thank you in advance, Morten
Risposta accettata
Più risposte (1)
Ankitha Kollegal Arjun
il 29 Dic 2016
Morten,
You could try the following:
1. Factorize the required symbolic expression using factor(). (result will be a symbolic vector)
2. Use the latex() function on each element of the above symbolic vector and concatenate the results to obtain the desired latex format.
>> syms x
>> str = (5/8)*x;
>> temp = factor(str);
>> out = [latex(temp(1)) latex(temp(2))]
out =
\frac{5}{8}x
1 Commento
MortenJ
il 30 Dic 2016
Categorie
Scopri di più su Common Operations in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!