printing complete mathematical equation

Hello All,
I am working with symbolic functions in live editor mode. What I want to do is that as I am calculating a function, I want the mathematical equation to be completely shown. I mean the right hand side of the equation be printed and left hand side will be calcualated and then printed.
syms m(t) n(t)
A=10*cos(m)+5*sin(n)
A(t) = 
diff(A,t)
ans(t) = 
for example, for above equation I want it to be shown as:
Is there a way to do this?

回答 (2 件)

Torsten
Torsten 2022 年 12 月 16 日

2 投票

syms m(t) n(t) A(t)
eqn = A==10*cos(m)+5*sin(n)
eqn(t) = 
deqn = diff(eqn,t)
deqn(t) = 

4 件のコメント

ali mohseni
ali mohseni 2022 年 12 月 16 日
編集済み: ali mohseni 2022 年 12 月 16 日
That was a good answer, but I think I just posted a bad example for this. Can you just give me your suggestion for this piece of code?
syms M K X(t)
L= M*diff(X,t)^2/2+K*X^2
L(t) = 
A1= simplify(diff(L,diff(X,t)))
A1(t) = 
A2= simplify(diff(diff(L,diff(X,t))))
A2(t) = 
A3= diff(L,X)
A3(t) = 
I want A1, A2, A3 to be shown as their mathematical expression. The thing here is that the LHS is not a seprate variable like A in the previous example, they are just a function of the defined L.
Walter Roberson
Walter Roberson 2022 年 12 月 16 日
Outside of the LiveScript (and MATLAB Answers), the best MATLAB can do is text formatting using pretty(). Fortunately for you, you are using the Live Editor, which can format nicely.
In each case, when you have variable = value and no semi-colon then LiveScript does not format the variable name nicely. For example,
syms A_1
A_2 = A_1
A_2 = 
Observe how the left side is completely unformatted but the right side is formatted.
In order to display a formatted left side, you could create an equation using == and display the equation... and ignore the fact that it displays the name of the equation as well as the nicely formatted display.
syms M K X(t) L(t)
Lfun = L(t);
L = M*diff(X,t)^2/2+K*X^2
L(t) = 
A1 = simplify(diff(L,diff(X,t)));
DLDX = diff(diff(Lfun,t),diff(X,t));
DLDX == A1
ans(t) = 
But notice the left side is 0. MATLAB noticed that that L(t) is not dependent on X(t) and so decided the derivative is 0.
So what can you do? Well, you can use displayFormula which will allow you to compose the form for the derivative without evaluating the derivative.
ali mohseni
ali mohseni 2022 年 12 月 16 日
編集済み: ali mohseni 2022 年 12 月 16 日
I just tried this. I faced two problems which are:
  • The RHS for the display formula could not be empty:
S = "m*diff(y,t,t) == m*g-k*y";
displayFormula(S)
S = "m*diff(y,t,t)=";
%displayFormula(S)
%Just uncomment the above command and you'll see the error.
  • Second as I defined L before, when I put L in the displayFormula command it just plugs in what I have defined for L.
syms M K X(t) L(t)
L = M*diff(X,t)^2/2+K*X^2
L(t) = 
S = "m*diff(L,X)=1"
S = "m*diff(L,X)=1"
displayFormula(S)
Do you know how I can solve these problems?
Walter Roberson
Walter Roberson 2022 年 12 月 16 日
syms M K X(t) L(t)
L = M*diff(X,t)^2/2+K*X^2
L(t) = 
S = "m*diff(L,X)=1"
S = "m*diff(L,X)=1"
displayFormula(S, sym([]), sym([])) %no substitutions

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

Torsten
Torsten 2022 年 12 月 16 日

0 投票

I don't know exactly what you mean.
syms M K X(t) %Physical Parameters
dX = diff(X,t);
L= M*dX^2/2+K*X^2
L(t) = 
A1 = diff(L,dX)
A1(t) = 
A2 = diff(diff(L,X),t)
A2(t) = 
A3 = diff(L,X)
A3(t) = 

3 件のコメント

ali mohseni
ali mohseni 2022 年 12 月 16 日
編集済み: ali mohseni 2022 年 12 月 16 日
Sorry for any confusion.I want the equations to be shown as below:
or
These are the equations that I am looking to print. Anything like this would work.
Torsten
Torsten 2022 年 12 月 17 日
編集済み: Torsten 2022 年 12 月 17 日
Not possible.
Use LaTex to write mathematical formulae in a text editor.
Walter Roberson
Walter Roberson 2022 年 12 月 18 日
You can create forms. It might take more work to get them pretty.
syms M X(t)
RHS = M*diff(diff(X(t),t),t);
S = "diff(diff(L,diff(X(t),t)),t) = RHS"
S = "diff(diff(L,diff(X(t),t)),t) = RHS"
displayFormula(S, sym('RHS'), RHS)

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

カテゴリ

ヘルプ センター および File ExchangeSymbolic Math Toolbox についてさらに検索

製品

リリース

R2022a

質問済み:

2022 年 12 月 16 日

コメント済み:

2022 年 12 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by