Convert a decimal approximation to exact value symbolically

3 vues (au cours des 30 derniers jours)
rezheen
rezheen le 26 Juin 2025
Commenté : Walter Roberson le 10 Juil 2025
Hi, I'm working with a definite integral and get a decimal approximation as my answer. I'd like to also get the exact solution:
syms x y
y1=sin(pi*x/2); y2=x; x1=-1; x2=1;
A=int((abs(y2-y1)),x1,x2);
Gives the answer as 0.2732 which is a correct decimal approximation. The exact solution is:
(4-pi)/pi
How do I get that?

Réponse acceptée

Torsten
Torsten le 26 Juin 2025
Déplacé(e) : Torsten le 26 Juin 2025
Here, you need the fact that y2-y1 is an odd function:
syms x y
y1=sin(pi*x/2); y2=x; x1=-1; x2=1;
A=2*int(y2-y1,x,x1,0)
A = 
  6 commentaires
Torsten
Torsten le 10 Juil 2025
if I have functions or areas without identical halves (odd?), I suppose there aren't exact solutions with the version I'm using.
Sometimes it works, sometimes not. The "abs" function is always problematic together with "int". And it doesn't have to do with your MATLAB version - it also doesn't work in R2024b as you can see above.
Walter Roberson
Walter Roberson le 10 Juil 2025
Huh, there appears to be a simplify bug.
syms x y
y1=sin(pi*x/2); y2=x; x1=-1; x2=1;
A=int((abs(y2-y1)),x1,x2)
A = 
simplify(A, 'steps', 50)
ans = 
vpa(A)
ans = 
0.27323954473516268615107010698011

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 8 Juil 2025
sympref('FloatingPointOutput',false);
Will display an unevaluated int() form for your original problem, and will display 4/pi - 1 for the version suggested by @Torsten
It seems that you have FloatPointOutput true in effect.

Tags

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by