Computing expint(x), where x is an array, locks up for some x but not others that are very similar
Ältere Kommentare anzeigen
Hi all,
I'm computing y = expint(x) where x is an array of doubles. In the attached data, x, there are two very similar arrays of data. Setting column 1 as x, the array y computes instantly. Setting column 2 as x, MATLAB gets stuck (or takes far longer than I'm willing to wait - order minutes). I can obtain the array y from column 2 iteratively, but it is much slower than array computation which will ultimately inhibit its utilization within the parent script.
Thinking the issue is with the values being slightly higher/lower in column 2 than column 1, I attempted the same test with repmat of said higher or lower values. y computed instantly in both instances.
Does anyone have any idea why column 2 does not compute but column 1, repmat(max(column 2),24001,1), and repmat(min(column 2),24001,1) compute without issue?
Thank you in advance.
2 Kommentare
Walter Roberson
am 26 Jul. 2023
I do not know why but it has something to do with x2(2124) and x2(23846)
x2(2125:23846) is fast, and x2(2124:23845) is fast, but when both of those endpoints are included, the computation is slow.
I can see nothing at all special about those values. They appear effectively linear in the surrounding data.
Scott
am 26 Jul. 2023
Akzeptierte Antwort
Weitere Antworten (1)
The computation of the second column is even faster. I wonder how matlab evaluates expint(x) if x is a vector different from evaluating the function for each x separately.
fileID = fopen('sampleData.txt','r');
formatSpec = '%f %f';
A = fscanf(fileID,formatSpec);
A = [A(1:2:end),A(2:2:end)];
n = 24001;
tic
for i = 1:n
expint(A(i,1));
end
toc
tic
for i = 1:n
expint(A(i,2));
end
toc
Kategorien
Mehr zu Mathematics 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!