MATLAB: Error in @(t)(yt.*e​xp(-sqrt(-​1).*omega.​*t));Error in integralCa​lc/iterate​ScalarValu​ed (line 314) fx = FUN(t);

integration

Can someone help me understand what the error in this code is please?
if true
format long
a = 1
b = 3*10.^-7
c = 5*10.^-8
f0 = 4*10.^9
sigma = 0.2
t0 = 0
tmax = 2.*b
f = linspace(10.^6, 10.^10)
omega = 2.*pi.*f
omega0 = 2.*pi.*f0
yt = a.*exp((-(t-b).^2)/((2*c).^2))
figure(1)
plot(t,yt)
fun = @(t) (yt.*exp(-sqrt(-1).*omega.*t))
q = integral(fun,0,6*10^-7)
% code
end
I'm trying to integrate fun and have tried many ways but I still cant get it.

Best Answer

This runs. You didn’t define ‘t’ in the code you posted, so I created it. Otherwise, I changed your integral call to specify your function to be 'ArrayValued'. I have no idea if it produces the result you want, so experiment with it:
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); % Created To Define ‘t’
omega = 2.*pi.*f;
omega0 = 2.*pi.*f0;
yt = a.*exp((-(t-b).^2)./((2*c).^2));
fun = @(t) (yt.*exp(-1i.*omega.*t));
q = integral(fun,0,6E-7, 'ArrayValued',1);
figure(1)
plot(t,yt)