Azzera filtri
Azzera filtri

fsolve with cell input?

4 visualizzazioni (ultimi 30 giorni)
Daniel Wells
Daniel Wells il 4 Nov 2011
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 Commenti
Sean de Wolski
Sean de Wolski il 4 Nov 2011
You'd have to show us the relevant code.
Walter Roberson
Walter Roberson il 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 .

Accedi per commentare.

Risposte (1)

Sean de Wolski
Sean de Wolski il 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.

Categorie

Scopri di più su Performance and Memory in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by