Integration error - "integrand F must return a single, real-valued vector of the same size as the input" - even when the integrand DOES return such a vector
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I call the following within a function:
Vsame = @(x) Vsame_fit(x./lB);
F0011 = @(x) (1-(x.^2)/2).*exp(-(x.^2./2));
integ_F0011same = @(x) F0011(x).*Vsame(x);
integ_F0011same(linspace(1,3,10))
Fsame(1,1,2,2) = quadcc(integ_F0011same,0,Inf);
I defined the constant lB elsewhere. Outside that function I have defined Vsame_fit:
function y = Vsame_fit(q)
for k=1:length(q)
if q(k)<0.022913
y(k) = 0.98*tanh(200*q(k));
elseif q(k)<0.50274
y(k) = 1/(0.9*q(k)+1);
elseif q(k)<21.598
y(k) = 1/(1.046*q(k)+0.9266);
else
y(k) = 1/(0.9512*q(k)+2.89);
end
end
end
I wrote the loop over the length of the argument to ensure that it would return a vector. Furthermore, if I call something simple as a test like
integ_F0011same(linspace(1,3,10))
inside the function, a 10-element is returned as expected. Why am I getting this error?
At the end of the day, I just want to have the value of the integral which I was hoping would be saved to Fsame(1,1,2,2). The reason I have defined things with so many separate functions, however, is that I reuse Vsame three more times to evaluate similar integrals, e.g.
integ_F0110same = @(x) F0110(x).*Vsame(x);
Fsame(1,2,2,1) = quadcc(integ_F0110same,0,Inf);
where F011(x) was also defined with a function handle. Is there a better way I should be doing this?
2 Kommentare
Matt J
am 7 Jun. 2019
Because quadcc is not a Mathworks-shipped function, you will probably have to ask its author.
Antworten (1)
Steven Lord
am 7 Jun. 2019
For what it's worth, when I defined your functions (with lB equal to 1, since you didn't specify a value) and called integral on it I received a result. Unless you're required to use quadcc, I'd just switch to integral.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!