Symbolic Math is reordering my subtraction
4 ビュー (過去 30 日間)
古いコメントを表示
I am using symbolic function to take the derivative. My funcitions are:
syms x_k(t) y_k(t) L
x_kD = diff(x_k,t)
y_kD = diff(y_k,t)
rRk = sqrt(x_k^2 + y_k^2)
rTk = sqrt(x_k^2 + (y_k-L)^2)
rRkD = simplify(diff(rRk,t))
rTkD = simplify(diff(rTk,t))
The problem is when you run the rRk term the syms math changes the order of subtraction around from y_k - L to L - y_k. This is throwing off the derivative as well where rTkD gets a minus sign in between the two terms in the numerator where is should be a positive. Is there a way to stop the switching of the subtraction in the variable of rTk and rTkD? Another thing that would be helpful is there a way to convert the time derivative that is output into the dot derivative form? Thank you in advance!
0 件のコメント
回答 (2 件)
John D'Errico
2021 年 2 月 25 日
編集済み: John D'Errico
2021 年 2 月 25 日
syms x_k(t) y_k(t) L
x_kD = diff(x_k,t)
y_kD = diff(y_k,t)
rRk = sqrt(x_k^2 + y_k^2)
rTk = sqrt(x_k^2 + (y_k-L)^2)
rRkD = simplify(diff(rRk,t))
rTkD = simplify(diff(rTk,t))
The swap in sign is irrelevant. This is true in mathematics:
a - b = - (b - a)
Well, it is true and always has been, unless something has changed in mathematics. However, you never know with the new math these days, and some boards of education.
As for a dot derivative form, MATLAB does not provide that form. It is purely a notational thing, so why do you feel you need it?
1 件のコメント
Steven Lord
2021 年 2 月 26 日
Not only that, (a-b)^2 is a*a-a*b-b*a+b*b. (b-a)^2 is b*b-b*a-a*b+a*a. Same terms, different order.
Walter Roberson
2021 年 2 月 26 日
Livescript only, you can use __dot as part of the symbol name. However, you cannot get the rendered form to appear on the left side, and it will not be put in automatically.
syms x(t) x__dot(t) x__dot_ y(t) y__dot
x__dot_ = diff(x)
y__dot_ = diff(y)
y = x__dot_^2 - y__dot_^2
subs(y, {x__dot_, y__dot_}, {x__dot, y__dot})
Notice the last line there has and that the looks nicer. But...
diff(ans,t)
y disappeared, because (no ) is not considered to be a function of t. For computation purposes, you cannot have it both ways, displaying without the (t) but being computed on the same symbols as if (t) were present
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Assumptions についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!