필터 지우기
필터 지우기

convert Matlab results to Latex

조회 수: 130 (최근 30일)
M
M 2022년 10월 24일
답변: Steven Lord 2022년 10월 25일
Hi all, I obtained some equations in Matlab's command window, and I have to write them in Latex, but because they are too long and hard to follow, I would like to know if there is any way to convert them directly to Latex. Please see the below formula. Thanks in advance for any help.
Dhf1=(c.^8.*kipr.*vplc.^2.*(ct.*gamma - c.*(gamma + 1)))./(ki.^2.*(kb.*kp.^2.*(c.^4 + kc.^4 - (c.^4.*kh.^4)./(c.^4 + kh.^4)) + (c.^8.*h.*vplc.^2.*(kb + 1))./(ki.^2.*(c.^2 + kplc.^2).^2)).*(c.^2 + kplc.^2).^2) - (c.^16.*h.*kipr.*vplc.^4.*(ct.*gamma - c.*(gamma + 1)).*(kb + 1))./(ki.^4.*(kb.*kp.^2.*(c.^4 + kc.^4 - (c.^4.*kh.^4)./(c.^4 + kh.^4)) + (c.^8.*h.*vplc.^2.*(kb + 1))./(ki.^2.*(c.^2 + kplc.^2).^2)).^2.*(c.^2 + kplc.^2).^4);

채택된 답변

Walter Roberson
Walter Roberson 2022년 10월 24일
Not exactly.
I can tell from the .^ that what you are showing is MATLAB code, not the output of the Symbolic Toolbox. There is no function provided that can convert from MATLAB code to Latex.
However if you have the Symbolic Toolbox, then
eqn = 'Dhf1=(c.^8.*kipr.*vplc.^2.*(ct.*gamma - c.*(gamma + 1)))./(ki.^2.*(kb.*kp.^2.*(c.^4 + kc.^4 - (c.^4.*kh.^4)./(c.^4 + kh.^4)) + (c.^8.*h.*vplc.^2.*(kb + 1))./(ki.^2.*(c.^2 + kplc.^2).^2)).*(c.^2 + kplc.^2).^2) - (c.^16.*h.*kipr.*vplc.^4.*(ct.*gamma - c.*(gamma + 1)).*(kb + 1))./(ki.^4.*(kb.*kp.^2.*(c.^4 + kc.^4 - (c.^4.*kh.^4)./(c.^4 + kh.^4)) + (c.^8.*h.*vplc.^2.*(kb + 1))./(ki.^2.*(c.^2 + kplc.^2).^2)).^2.*(c.^2 + kplc.^2).^4)';
symeqn = str2sym(eqn)
symeqn = 
latex(symeqn)
ans = '\mathrm{Dhf}_{1}=\frac{c^8\,\mathrm{kipr}\,{\mathrm{vplc}}^2\,\left(\mathrm{ct}\,\gamma -c\,\left(\gamma +1\right)\right)}{{\mathrm{ki}}^2\,\left(\mathrm{kb}\,{\mathrm{kp}}^2\,\left(c^4+{\mathrm{kc}}^4-\frac{c^4\,{\mathrm{kh}}^4}{c^4+{\mathrm{kh}}^4}\right)+\frac{c^8\,h\,{\mathrm{vplc}}^2\,\left(\mathrm{kb}+1\right)}{{\mathrm{ki}}^2\,{\left(c^2+{\mathrm{kplc}}^2\right)}^2}\right)\,{\left(c^2+{\mathrm{kplc}}^2\right)}^2}-\frac{c^{16}\,h\,\mathrm{kipr}\,{\mathrm{vplc}}^4\,\left(\mathrm{ct}\,\gamma -c\,\left(\gamma +1\right)\right)\,\left(\mathrm{kb}+1\right)}{{\mathrm{ki}}^4\,{\left(\mathrm{kb}\,{\mathrm{kp}}^2\,\left(c^4+{\mathrm{kc}}^4-\frac{c^4\,{\mathrm{kh}}^4}{c^4+{\mathrm{kh}}^4}\right)+\frac{c^8\,h\,{\mathrm{vplc}}^2\,\left(\mathrm{kb}+1\right)}{{\mathrm{ki}}^2\,{\left(c^2+{\mathrm{kplc}}^2\right)}^2}\right)}^2\,{\left(c^2+{\mathrm{kplc}}^2\right)}^4}'
Unfortunately there is no method provided to take that dynamic output and display it in formatted form.
If you happen to be using LiveScript, then what I show here as symeqn would be automatically displayed nicely -- same as what you see here in this Answer. (There is also a sympref() to disable abbreviating the expression by moving out to a separate expression on display.)
  댓글 수: 1
M
M 2022년 10월 25일
Thank you so much.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Steven Lord
Steven Lord 2022년 10월 25일

카테고리

Help CenterFile Exchange에서 LaTeX에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by