
Simplifying a matematical expression
2 次查看(过去 30 天)
显示 更早的评论
I have this following beastly expression typed up very nicely in LaTeX formatting, as you can see. Is there anyway that I can enter this into Matlab to simplify it?? I feel like even if I type it in, then it will be hard for me to know if I typed in the correct expression. How do i simplify this beast!? Thank you!
$W_{(1,1)}(t,v)=\frac{-t^{-2k}v^k}{3}(\frac{v^{\frac{3}{2}}-v^{\frac{-3}{2}}}{t^{\frac{3}{2}}-t^{\frac{-3}{2}}})(\frac{v^{\frac{1}{2}}-v^{\frac{-1}{2}}}{t^{\frac{1}{2}}-t^{\frac{-1}{2}}})+\frac{t^{-2k}v^k}{4}(\frac{v-v^{-1}}{t-t^{-1}})^2+\frac{t^{-2k}v^k}{12}(\frac{v^{\frac{1}{2}}-v^{\frac{-1}{2}}}{t^{\frac{1}{2}}-t^{\frac{-1}{2}}})-\frac{t^{-k}v^k}{4}(\frac{v^2-v^{-2}}{t^2-t^{-2}}) + \frac{t^{-k}v^k}{8}(\frac{v-v^{-1}}{t-t^{-1}})^2+\frac{t^{-k}v^k}{4}(\frac{v-v^{-1}}{t-t^{-1}})(\frac{v^{\frac{1}{2}}-v^{\frac{-1}{2}}}{t^{\frac{1}{2}}-t^{\frac{-1}{2}}})^2-\frac{t^{-k}v^k}{8}(\frac{v^{\frac{1}{2}}-v^{\frac{-1}{2}}}{t^{\frac{1}{2}}-t^{\frac{-1}{2}}})^4+\frac{-v^kt^{k}}{4}(\frac{v^2-v^{-2}}{t^2-t^{-2}})+\frac{v^kt^{k}}{3}(\frac{v^{\frac{3}{2}}-v^{\frac{-3}{2}}}{t^{\frac{3}{2}}-t^{\frac{-3}{2}}})(\frac{v^{\frac{1}{2}}-v^{\frac{-1}{2}}}{t^{\frac{1}{2}}-t^{\frac{-1}{2}}})+\frac{v^kt^{k}}{8}(\frac{v-v^{-1}}{t-t^{-1}})^2-\frac{v^kt^{k}}{4}(\frac{v-v^{-1}}{t-t^{-1}})(\frac{v^{\frac{1}{2}}-v^{\frac{-1}{2}}}{t^{\frac{1}{2}}-t^{\frac{-1}{2}}})^2+\frac{v^kt^{k}}{24}(\frac{v^{\frac{1}{2}}-v^{\frac{-1}{2}}}{t^{\frac{1}{2}}-t^{\frac{-1}{2}}})^4$
0 个评论
回答(1 个)
Steven Lord
2020-9-17
After inserting it into Answers using the sigma button on the toolstrip:

Honestly, I wouldn't enter this as one term. As you called out, there's a decent amount of risk in missing a term or typing it in incorrectly. I'd enter it in one term or one part of a term at a time.
function result = W11(t, v)
k = 2; % Arbitrarily chosen value
% These expressions are used quite often, so compute them once and reuse the shorter expressions
sv = sqrt(v);
sv3 = sv.^3;
st = sqrt(t);
st3 = st.^3;
term(1) = -(t.^(-2*k).*(v^k))/3 * (sv3-1./sv3)./(st3-1./st3) * (sv-1./sv)./(st-1./st);
term(2) = ...
% Continue with the rest of the terms
result = sum(term);
end
This way if there's a problem with one of the terms its individual piece can be debugged more easily. You could even compute more of the common subexpressions once like I did with sv, sv3, etc. The expression (sv-1./sv)./(st-1./st) looks like it occurs frequently so it may be a good candidate.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!