Error in @(t)(yt.*exp(-sqrt(-1).*omega.*t));Error in integralCalc/iterateScalarValued (line 314) fx = FUN(t);
Ältere Kommentare anzeigen
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.
Akzeptierte Antwort
Weitere Antworten (1)
Walter Roberson
am 6 Aug. 2015
Your omega is 1 x 100. For omega.*t to work, your t would have to be either scalar or 1 x 100. But http://www.mathworks.com/help/matlab/ref/integral.html#inputs
For scalar-valued problems, the function y = fun(x) must accept a vector argument, x, and return a vector result, y.
That is, the value passed in (your "t") will be a vector of arbitrary length and you need to return a value for each entry in "t". But your omega is length 100 so which one value do you want to return?
Perhaps you want each integral call to be a single t and that you return one value for each omega. If so then pass 'ArrayValued', 1 to the int() call:
q = integral(fun,0,6*10^-7, 'ArrayValued', 1);
I note, though, that you define yt in terms of t, and you do so at a point that t is not defined. Is the t there intended to be the same t as in fun? If so then you need to define yt as a function and invoke it as a function:
yt = @(t) a.*exp((-(t-b).^2)/((2*c).^2));
fun = @(t) (yt(t).*exp(-sqrt(-1).*omega.*t));
q = integral(fun,0,6*10^-7, 'ArrayValued', 1);
This will return q the same size as omega; the values in q will be complex.
2 Kommentare
imarquez
am 7 Aug. 2015
Walter Roberson
am 7 Aug. 2015
Yes, you have 2*pi*f and f is length 100 so the outcome is length 100
Kategorien
Mehr zu Frequency Transformations finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!