how i can show in matlab tha sqrt(x^2)=x in symbolic toolbox
5 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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)
rhs = (2*A*dhmax+B*h0)/h0
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)
In that case, asking MATLAB to simplify the expression may allow it to perform the rewriting you want.
1 个评论
Shubham
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 ))
更多回答(1 个)
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)
simplify(expression)
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)
1 个评论
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!