Finding minimum values for two-unknown equation!!!
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Serhat
am 21 Mai 2014
Bearbeitet: Star Strider
am 23 Mai 2014
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/163155/image.jpeg)
Hello,
'a' 'b' 'c' 'd' are known in the equation. We are trying to find values for 'x' and 'y' that minimizes 'F'
Is it possible to insert this function directly in to Matlab? If yes, how can we minimize?
Thanks
0 Kommentare
Akzeptierte Antwort
Star Strider
am 21 Mai 2014
This works:
a = 3;
b = 5;
c = 7;
d = 13;
% % x = xy(1), y = xy(2)
F = @(xy) hypot(xy(1)-a, xy(2)-b) + hypot(xy(1)-c, xy(2)-d)
[xy, fval] = fminsearch(F,[1 1])
4 Kommentare
Star Strider
am 23 Mai 2014
Bearbeitet: Star Strider
am 23 Mai 2014
You have two errors that I see that will cause your loop to fail:
- Don’t define F as F(ti,:). Just define it as F and then call it as F in fminsearch. Also, F(ti,:) or F should not be on the right side of the equation. You are correct in putting it in the loop, since apparently you are defining different constants ( r, BS ) in it. Test F outside the loop on one set of parameters before you put it in the loop, then with fminsearch. That way, you know it works, what it returns, and that it works with fminsearch.
- In your fminsearch output in the loop, xy has 2 elements ( x and y ), so return it as either [xy(ti,:),fval] or [xy(:,ti),fval] depending on whether it returns xy at each iteration as a row or column vector. Also, I suggest you store fval as well, so you know the function minimum at each iteration. This may be of interest to you later.
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!