fsolve with cell input?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
As a continuation of an earlier question, I am now trying to find the minimum of a function f from R^n to R^n. I have figured out a way to make this function flexible in terms of n (an anonymous function which essentially takes in a vector input, converts the vector to a cell array, and has f evaluate that cell array), but when I minimize this anonymous function using fsolve, it is slow, due to all of the calls to fsolve, each of which call the function mat2cell. Furthermore, fsolve can apparently not take as input a cell array. Is it possible to eliminate the need for mat2cell (and the anonymous function) and maintain the complete flexibility of my code?
2 Kommentare
Walter Roberson
am 4 Nov. 2011
Are you sure that f is R^n to R^n ? It is difficult to define what it means to minimize a function whose range is not R^1 .
Antworten (1)
Sean de Wolski
am 4 Nov. 2011
Using num2cell if you're only concatenating along one dimension is significantly faster. E.g:
A = magic(1000);
t1 = 0;
t2 = 0;
for ii = 1:50
tic
B = mat2cell(A,ones(1,1000),1000);
t1 = t1+toc;
tic
C = num2cell(A,2);
t2 = t2+toc;
end
isequal(B,C)
t1/t2
I'm seeing about a 15% increase in speed with this matrix.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Numeric Types finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!