Chloe Carmichael
Chloe Carmichael

Reputation: 35

Matlab How to plot integrals

I am trying to plot the Fresnel Integrals on matlab

x(t) = ∫ cos(v^2)dv bounds: a = 0, b = t y(t) = ∫ sin(u^2)du bounds: a = 0, b = t

plot: x(t) vs y(t) for -4pi <= t <= 4pi

I have been looking online for how to do this but cannot get anywhere useful on how to even start this problem. Anything will help even if its just pointing me in the right direction. Thanks in advance.

Upvotes: 0

Views: 1927

Answers (1)

user3717023
user3717023

Reputation:

This is a tricky plot (I'm assuming it comes from a numerical methods assignment). The functions to be integrated are highly oscillatory: here is sin(x^2) on the interval 0 to 4*pi.

sin(x^2)

Within this range, it's still practical to integrate using the fixed step size, but it needs to be pretty small: I'd pick h=0.001. Also, to increase precision I recommend modifying cumsum (which corresponds to "left/right endpoint" methods of integration) so that it implements the trapezoidal method. This means removing 1/2 of the leftmost and the rightmost values used in the sum.

As an illustration, I give a sample program that plots from 0 to 4*pi, leaving for you to adapt this to your range. (You don't necessarily have to compute more integrals if you use the fact that the integrands are even.)

h = 0.001;
t = 0:h:4*pi;
x = cos(t.^2);
y = sin(t.^2);
X = h*(cumsum(x)-x(1)/2-x/2);
Y = h*(cumsum(y)-y(1)/2-y/2);
plot(X,Y)

plot

Remarks

  • Although not necessary, it would help to change the variable of integration s=v^2, because then the oscillations happen with the same period, which fits this fixed step-size approach better.

  • This is the kind of situation in which one can consider an adaptive integration method.

Upvotes: 1

Related Questions