필터 지우기
필터 지우기

Find argmin of function with unique vector

조회 수: 6 (최근 30일)
DM
DM 2019년 6월 23일
댓글: DM 2019년 6월 26일
Hi,
I want to solve the next problem:
For example, for and
I tried to do some things like:
x=[theta,1-theta];
x0 =[0.0001,0.0001];
fun = @(x)sum((x-y)./x);
x = fminsearch(fun,x0);
Any idea how to minimize vector with respect to this scalar?
I know I can just write it like that:
x0 =[0.0001,0.0001];
fun = @(x) (x-y(1))/x + ((1-x)-y(2))/x
x = fminsearch(fun,x0);
But there are more dimensions (then 2) in the original problem so it is impractical to do so.
Thanks!
  댓글 수: 3
DM
DM 2019년 6월 25일
Hi,
N is the dimenstion of the problem and n is the n'th value of the vector.
In the example above N=2 and and
Kaustav Bhattacharya
Kaustav Bhattacharya 2019년 6월 25일
If you know n can you not use
x0 = ones(1,n)*0.0001
and then
x = fminsearch(fun,x0) ?

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

채택된 답변

Matt J
Matt J 2019년 6월 25일
You need to write code that generates in vectorized form. Then the rest is easy. The correct way to code your original example is,
f= @(theta) [theta,1-theta];
objective = @(theta)sum((f(theta)-y)./f(theta));
x = fminsearch(objective,0.0001);
  댓글 수: 1
DM
DM 2019년 6월 26일
That's what I needed, thank you!!

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

추가 답변 (1개)

infinity
infinity 2019년 6월 25일
편집: infinity 2019년 6월 25일
Hello,
Here is an example that you can refer
I find mininum of function , the initial guess is given by . The code could be like that
clear
N = 5;
fun = @(t) norm(t,2);
x0 = 1+zeros(1,N);
x = fminsearch(fun,x0)
where I choose N = 5, but it can be changed.
  댓글 수: 2
DM
DM 2019년 6월 25일
You can write
x0=ones(1,N);
But it doesn't help me since I need to find the minimum of theta from the minimum probelm above.
infinity
infinity 2019년 6월 25일
Yes, it is an idea how to solve problem with mutil-dimensiona. You may adapt the code for your case.

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

Community Treasure Hunt

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

Start Hunting!

Translated by