How to get simplified, symbolic solutions for definite integrals

9 views (last 30 days)
Hi,
I have a function:
which I integrate over the whole real line, and then divide by pi. The below code:
syms x w
fn1 = exp(-abs(x))*cos(w*x)
int(fn1, x, [-inf inf])/pi
produces the following output:
Which is probably not incorrect, but I was hoping to see what Python (SymPy) would cleanly give as:
I tried to 'simplify' or to play with format, but, to be honest, I am not even sure what to look for in documentation. My issue is most likely due to trying to run before I can walk. That is to say, after recently having aquired Matlab (student, doing another degree late in life), I never did spend months on learning all of its basics, and am instead relying on 40 years of general programming and math experience. Clearly not enough in this case, though :)
Could I get a few pointers, please, as to how to get Matlab results to be in a fully symbolic, rational (1/3 instead of 0.333333), simplified (cos^2 + sin^2 = 1) kind of mode?

Accepted Answer

Paul
Paul on 15 Apr 2022
Edited: Paul on 15 Apr 2022
Declare x w to be real
syms x w real
fn1 = exp(-abs(x))*cos(w*x)
fn1 = 
int(fn1, x, [-inf inf])/sym(pi)
ans = 

More Answers (0)

Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!