Fminsearch for matrices

Hi, how can i use fminsearch function for more than one dimension.
I am trying to do some thing like f=@(X)min(A-B*X), where A and B are given matrices. When I try to do fminsearch(f,x) i get the following error
??? Error using ==> minus Matrix dimensions must agree
so is there a way? Thanks

 채택된 답변

Andrew Newell
Andrew Newell 2011년 4월 21일

0 개 추천

It sounds like the problem is with the dimensions of B*X. Does your initial value x0 have the same dimensions as A and B?

댓글 수: 4

srinadh
srinadh 2011년 4월 21일
so let me give u a sample code.
A=[1;1];
B=[2,1;4,3];
f=@(X)(A-B*X);
fminsearch(f,[1;2]);
srinadh
srinadh 2011년 4월 21일
surprising thing is that when I define f=@(X)(A-B*[X(1);X(2)]); I still get an error. But for f=@(X)norm(A-B*[X(1);X(2)]);, it works perfectly!
Andrew Newell
Andrew Newell 2011년 4월 21일
Ah, I see the problem. FMINSEARCH can only accept functions that have a scalar as output. Fortunately, the function with the norm in it seems to be what you want.
srinadh
srinadh 2011년 4월 21일
Oh, that's the issue. Thanks for the help :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

태그

Community Treasure Hunt

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

Start Hunting!

Translated by