How to avoid introducing abs( ) when simplifying expressions using the symbolic toolbox ?

6 ビュー (過去 30 日間)
Prajwal Gowdru Shanthamurthy
Prajwal Gowdru Shanthamurthy 2021 年 12 月 1 日
回答済み: Walter Roberson 2021 年 12 月 2 日
%% Problem 6.4
syms x y x_dot y_dot
assume(x,'real');
assume(y, 'real');
assume(x_dot, 'real');
assume(y_dot, 'real');
%% Newtonian:
r_bar_cart = [x ; -log(cos(x)); 0];
v_bar_cart = x_dot*diff(r_bar_cart,x);
norm_v = sqrt(sum(v_bar_cart.^2));%magnitude of velocity
e_t_cap =simplify((v_bar_cart/norm_v),'Criterion','preferReal');
e_n = simplify(x_dot*diff(e_t_cap,x),'Criterion','preferReal');
I've declared the variables as real and set the simplification criterion to prefer real arguments. Still ending up with abs() in the expression for e_t_cap.

回答 (2 件)

David Goodmanson
David Goodmanson 2021 年 12 月 2 日
編集済み: David Goodmanson 2021 年 12 月 2 日
Hello Prajwal,
norm_v = abs(xdot)/abs(cos(x))
so it does fundamentally depend on abs. Since norm_v is being divided into quantites such as v_bar_cart that do not involve abs, there is no getting around the fact that the final results depend directly on abs. What kind of result are you looking for instead?
One thing that comes to mind is, e.g. using sqrt(xdot^2)) in place of abs(x) (with the assumption that sqrt picks the positive root by default). But that's no improvement unless you are not allowed to use abs for some reason, and I have doubts that you could coerce the symbolic toolbox into doing that.
  1 件のコメント
Walter Roberson
Walter Roberson 2021 年 12 月 2 日
You can use mapSymType to remap abs(expression) into sqrt(expression^2) if there was need.

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


Walter Roberson
Walter Roberson 2021 年 12 月 2 日
%% Problem 6.4
syms x y x_dot y_dot
assume(x,'real');
assume(y, 'real');
assume(x_dot, 'real');
assume(y_dot, 'real');
%% Newtonian:
r_bar_cart = [x ; -log(cos(x)); 0]
r_bar_cart = 
v_bar_cart = x_dot*diff(r_bar_cart,x)
v_bar_cart = 
norm_v = sqrt(sum(v_bar_cart.^2)) %magnitude of velocity
norm_v = 
e_t_cap =simplify((v_bar_cart/norm_v),'Criterion','preferReal')
e_t_cap = 
e_n = simplify(x_dot*diff(e_t_cap,x),'Criterion','preferReal')
e_n = 
rewrite(e_t_cap, 'sqrt')
ans = 
rewrite(e_n, 'sqrt')
ans = 

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by