how i can show in matlab tha sqrt(x^2)=x in symbolic toolbox
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
george veropoulos
le 22 Sep 2024
Commenté : Shubham
le 22 Sep 2024
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 commentaires
Réponse acceptée
Steven Lord
le 22 Sep 2024
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 commentaire
Shubham
le 22 Sep 2024
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 ))
Plus de réponses (1)
John D'Errico
le 22 Sep 2024
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 commentaire
John D'Errico
le 22 Sep 2024
Modifié(e) : John D'Errico
le 22 Sep 2024
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.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!