Effacer les filtres
Effacer les filtres

Plotting the integral without getting negative domain results?

2 vues (au cours des 30 derniers jours)
imarquez
imarquez le 10 Août 2015
Commenté : Walter Roberson le 11 Août 2015
So I need to graph the magnitude of equation 2 (I labeled them in the comments) but I am not getting what is expected for the plots of the magnitudes of equation 2. It should be a graph that starts out at some y value that is high up on the y scale, and then over the frequency (which is the x value) gradually slope down in a curved fashion till it hits 0. an easy way to describe what I am supposed to get would be an upside down e^x graph. Does anyone have any suggestions as to what I need to do to my code to get these results? I have been struggling trying to get the right result now for a week. :/
if true
format long
a = 1
b = 3E-7
c = 5E-8
f0 = 4E9
sigma = 0.2
t0 = 0
tmax = 2.*b
f = linspace(1E6,1E10)
t = linspace(t0, tmax)
omega = 2.*pi.*f
omega0 = 2.*pi.*f0
yt = a.*exp((-(t-b).^2)./((2*c).^2)) % equation (1)
fun = @(t) (yt.*exp(-1i.*omega.*t))
q = abs(integral(fun,0,6E-7, 'ArrayValued',1)) % equation (2)
figure(1)
plot(t,yt) % plot of (1) vs time for t:(0 to 6*10^-7)
figure(2)
plot(f,q) % plot of magnitude of F (eq 2) vs frequency for f:(10^6 to 10^10)
r = q.^2 % square of magnitude of F
figure(3)
plot(f,r) % plot of square of magnitude of F
q2 = integral(@(t) fun(t).^2,3.8E9,4.3E9, 'ArrayValued',1) % integral of square of magnitude of F
figure(4)
plot(f,q2)
% code
end
Here's part of my code that includes what I was talking about above. Any input on what I could do to get the correct result will be highly appreciated!

Réponses (2)

Walter Roberson
Walter Roberson le 10 Août 2015
A) You need to increase your resolution beyond the default number of points that linspace() generates
B) your fun is imaginary. squaring it is still imaginary. The integral of an imaginary quantity is imaginary and dependent upon the integration path. You should have noticed the
Warning: Imaginary parts of complex X and/or Y arguments ignored
  2 commentaires
imarquez
imarquez le 10 Août 2015
I put the first integral in absolute value form though, wouldn't that make the second integral also in absolute value form? I just updated my code to include it in the second integral anyways.
How do I increase the resolution?
Walter Roberson
Walter Roberson le 10 Août 2015
Your second integral is
integral(@(t) fun(t).^2,3.8E9,4.3E9, 'ArrayValued',1)
which does not use the value of the first integral. And your fun(t) is imaginary.

Connectez-vous pour commenter.


Star Strider
Star Strider le 10 Août 2015
See if substituting with this assignment does what you want:
q2 = integral(@(t) fun(t).*conj(fun(t)),3.8E9,4.3E9, 'ArrayValued',1);
  10 commentaires
Star Strider
Star Strider le 11 Août 2015
If double variables return NaN and 0, how do you know the uint64 values that do not are accurate? I would stay with double variables, and look closely at the code to see where the errors are if the results are not supposed to be 0. The minimum double-precision floating-point number is 2.2E-308.
Walter Roberson
Walter Roberson le 11 Août 2015
So you are using uint64() just because uint64(0)/uint64(0) returns 0 instead of NaN? Why are you not using
X(isnan(X)) = 0;
replacing the NaN with 0
Or perhaps when you do the division A./B,
Bz = B;
Bz(Bz==0) = 1;
A./Bz
so that you divide by 1 instead of 0 in that location, getting 0 as the output ?

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by