フィルターのクリア

How can I set the numbers of decimals (precision) of the solution of fminunc?

21 ビュー (過去 30 日間)
Patricia Mares Nasarre
Patricia Mares Nasarre 2017 年 12 月 13 日
編集済み: Romina Jahangiri 2021 年 2 月 18 日
I am minimizing a multivariable function using fminunc and I am interested in a solution with just two decimals (ex. A=3.04, not A=3.0421). This is because I am minimizing the error through calibrating some coefficients and I want those coefficients to have a certain precision.
  6 件のコメント
Birdman
Birdman 2017 年 12 月 13 日
Ok same thing:
CG=vpa(CG,3);
at the end of your code
Patricia Mares Nasarre
Patricia Mares Nasarre 2017 年 12 月 13 日
It does not work: it transforms the CG vector in a symbolic matrix with no numbers

サインインしてコメントする。

回答 (4 件)

KL
KL 2017 年 12 月 13 日
編集済み: KL 2017 年 12 月 13 日
  1 件のコメント
Patricia Mares Nasarre
Patricia Mares Nasarre 2017 年 12 月 13 日
編集済み: Patricia Mares Nasarre 2017 年 12 月 13 日
I have already tried it and I obtain the following error: Error using optimoptions (line 124) Unmatched parameter name 'StepTolerance ' must be a string scalar or character vector that can represent a field name. I have also tried to use 'TolX' with optimset, but the result is still showing so many decimals.

サインインしてコメントする。


Alan Weiss
Alan Weiss 2017 年 12 月 13 日
It is very difficult to know how the option settings affect the resulting solution accuracy. The only solver I know that is reasonably straightforward this way is patternsearch, and even that solver can be fooled.
My suggestion is simply to leave the options at their default values, if the process is not taking excessive time. If you want answers much faster than you currently are getting, first I would try to give better initial points x0, and only afterward gradually relax the step tolerance or optimality tolerance. But be careful, relaxed tolerances can have unwanted consequences, such as convergence to a point that is very far from optimal.
Alan Weiss
MATLAB mathematical toolbox documentation
  3 件のコメント
Alan Weiss
Alan Weiss 2017 年 12 月 13 日
I think that I still might not really understand what you want. If it is a display issue, you can choose to show only those decimal values that you like. See format or fprintf. If you want to control the solver iterations themselves, then I suggest again that you not try to do that, unless the solver is taking way too long.
Alan Weiss
MATLAB mathematical toolbox documentation
Patricia Mares Nasarre
Patricia Mares Nasarre 2017 年 12 月 13 日
It is not about the speed of the computational speed or a display issue. I want the minimum error (function to minimize) with coefficients with just two decimals

サインインしてコメントする。


John D'Errico
John D'Errico 2017 年 12 月 13 日
編集済み: John D'Errico 2017 年 12 月 13 日
"I want the solver to "jump" from 0.53 to 0.54 between iterations (minimum step), so the solution has 2 decimals and it doesn't look like: parameter=0.5321"
That is a discrete problem. Essentially, you want the solver to look at only a set of integer values, and fminunc is NOT such a solver. (I know, they are not integers that you want. Multiply them by 100, and they would be integers.)
The point is, you cannot use fminunc to solve that problem.
You CAN use tools that can handle optimization over an integer set. I recall GA is such a solver. intlinprog also allows a partially integer search space, if linear programming is an option.
  3 件のコメント
John D'Errico
John D'Errico 2017 年 12 月 13 日
If awful, that may just indicate you don't know how to use the tool properly.
As far as controlling the "step" of the parameters. Require integers, then divide by 100. WTP?
Patricia Mares Nasarre
Patricia Mares Nasarre 2017 年 12 月 13 日
The relationship with the coefficients is not linear, so it is not that straight forward.
I would also like to obtain results with diferent precisions, such as values ended in 0 and 5 (0.45, 0.50...)

サインインしてコメントする。


Romina Jahangiri
Romina Jahangiri 2021 年 2 月 18 日
編集済み: Romina Jahangiri 2021 年 2 月 18 日
I have same problem. I want to get 2 digits after decimal point in the result of fmincon. Did you solve your problem?

製品

Community Treasure Hunt

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

Start Hunting!

Translated by