필터 지우기
필터 지우기

fsolve with cell input?

조회 수: 4 (최근 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 CenterFile Exchange에서 Performance and Memory에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by