fsolve with cell input?
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2011-11-4
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 .
回答(1 个)
Sean de Wolski
2011-11-4
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Numeric Types 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!