how i can show in matlab tha sqrt(x^2)=x in symbolic toolbox

8 ビュー (過去 30 日間)
george veropoulos
george veropoulos 2024 年 9 月 22 日
コメント済み: Gojo 2024 年 9 月 22 日
Hi i use the symbolic tool box to simplify an expression I
receive that
((2*A*dhmax + B*h0)^2/h0^2)^(1/2)*(2*A^2*dhmax^2 + 2*A*B*dhmax*h0 + 6*C*A*h0^2 - B^2*h0^2))/(24*A^2*h0^2) - (((2*A*dhmax - B*h0)^2/h0^2)^(1/2)*(2*A^2*dhmax^2 - 2*A*B*dhmax*h0 + 6*C*A*h0^2 - B^2*h0^2))/(24*A^2*h0^2)
how i can say in matlab that ((2*A*dhmax + B*h0)^2/h0^2)^(1/2)= (2*A*dhmax+B*h0)/h0 ?
thank you
George

採用された回答

Steven Lord
Steven Lord 2024 年 9 月 22 日
That's not true in the general case.
A = 1;
h0 = 1;
dhmax = 2;
B = -5;
lhs = ((2*A*dhmax + B*h0)^2/h0^2)^(1/2)
lhs = 1
rhs = (2*A*dhmax+B*h0)/h0
rhs = -1
If you defined those variables to all be real and positive and used sqrt (so it's the principal square root):
syms A h0 dhmax B real positive
isAlways(sqrt((2*A*dhmax + B*h0)^2/h0^2) == (2*A*dhmax+B*h0)/h0)
ans = logical
1
In that case, asking MATLAB to simplify the expression may allow it to perform the rewriting you want.
  1 件のコメント
Gojo
Gojo 2024 年 9 月 22 日
If all the defined variables are not positive to begin, then atleast the entire expression should be positive:
syms A h0 dhmax B real;
expr = sqrt((2*A*dhmax + B*h0)^2/h0^2);
simplifiedExpr = simplify(expr);
disp(simplifiedExpr);
isAlways(simplifiedExpr == abs( (2*A*dhmax+B*h0)/h0 ))
ans = logical
1

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

その他の回答 (1 件)

John D'Errico
John D'Errico 2024 年 9 月 22 日
Except, that equality does NOT hold! The sqrt "function" has two branches. sqrt(x^2) can as easily be -x, as it is x. So you cannot simply replace sqrt(x^2) with x.
syms A dhmax B h0
expression = ((2*A*dhmax + B*h0)^2/h0^2)^(1/2)
expression = 
simplify(expression)
ans = 
As you can see, simplify refuses to do what you think is obvious. However, if you want, you can effectively tell simplify to play a little fast with the rules, to not be quite so picky.
simplify(expression,IgnoreAnalyticConstraints = true)
ans = 
  1 件のコメント
John D'Errico
John D'Errico 2024 年 9 月 22 日
編集済み: John D'Errico 2024 年 9 月 22 日
Sadly, Answers is again bugged, and for some strange reason will not allow me to show the results of those operations. But it does do what you want. SIGH. It does not help if I change browsers. It does not help if I clear all history. It does not help if I empty the browser caches.
The IgnoreAnalyticConstraints flag does what you want, however.

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

カテゴリ

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

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by