MATLAB: How to plot an expression which contains integral

integralintegrationplotplotting

Hi, I would like to plot the real and the imaginary part of the following expression without computing the integral separately. I haven't been able to figure out a way to plot this expression. Can you help me?

Best Answer

This code will numerically integrate the expression, and plot real and imaginary part.
exponentTerm1 = @(x_) 2-x_.^2;
exponentTerm2 = @(x_) cos(pi*x_/2)./(2-x_.^2);
exponent = @(x) 1i*integral(exponentTerm1, -1, x) + integral(exponentTerm2, -1, x);
f = @(x) exp(exponent(x));
x = -1:0.1:sqrt(2);
y = arrayfun(f, x);
subplot(211)
plot(x, real(y));
title('real')
subplot(212)
plot(x, imag(y));
title('imaginary')