Please find error in this 1-line code: I'm using the <int> function for integration.

1 view (last 30 days)
Please find error in this code: I'm using the int function for integration.
>> syms k
>> int(exp(-k)*cos(k),0,1)
This works, but...
>> syms k
>> int(exp(-k^2)*cos(k),0,1)
this does not work... I don't know what is wrong with this... I'm so frustrated...
Please help me.

Accepted Answer

Star Strider
Star Strider on 5 May 2014
The problem is that int(exp(-k^2)) is essentially the ‘error function’. To the best of my knowledge, it has no closed-form analytic solution. Taking the Taylor series of the integrand and then integrating it seems to work:
syms k
f = exp(-k^2)*cos(k);
ft = taylor(f, k, 'Order',11)
ift = int(ft, k, 0, 1)
produces:
ift =
26172299/39916800
Experiment with it until you get the result you want.

More Answers (0)

Categories

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

Community Treasure Hunt

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

Start Hunting!