fsolve with cell input?

5 ビュー (過去 30 日間)
Daniel Wells
Daniel Wells 2011 年 11 月 4 日
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 件のコメント
Sean de Wolski
Sean de Wolski 2011 年 11 月 4 日
You'd have to show us the relevant code.
Walter Roberson
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
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.

カテゴリ

Help Center および File ExchangeNumeric Types についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by