フィルターのクリア

Simplifying a matematical expression

1 回表示 (過去 30 日間)
Michael Vaughan
Michael Vaughan 2020 年 9 月 17 日
コメント済み: Michael Vaughan 2020 年 9 月 17 日
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$

回答 (1 件)

Steven Lord
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.
  2 件のコメント
Michael Vaughan
Michael Vaughan 2020 年 9 月 17 日
Thanks man, this helps a ton. I have 0 programming experience so what you've showed here really helps.
Michael Vaughan
Michael Vaughan 2020 年 9 月 17 日
Exscuse me, but I am trying to get this code to run and I am having issues. Even when I deleted the part about term(2), so the result should just give term(1) as the output. I'm getting the following error:
function result = W11(t, v)
Error: Function definition not supported in this context.
Create functions in code file.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeVariables についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by