MATLAB Answers

Rounding errors when using quadprog

3 ビュー (過去 30 日間)
Willem Aarts
Willem Aarts 2021 年 10 月 22 日
回答済み: Matt J 2021 年 10 月 22 日
When using quadprog, my output vector consists of numbers between 0 and 1 (what I wanted), but the numbers that should be exactly 0 are displayed as below. Obviously, I want all those very small numbers to be exactly zero, is there a way to do this (besides using round)?
4.44933945790336e-17
4.43024857154471e-17
1.38794710581954e-16
9.76943947509898e-17
2.57912017416732e-17
1.12856039637895e-16
2.51735116865162e-16
3.04176974448411e-17
9.76031101698955e-17
8.82231674489508e-17
1.93623111616387e-17
4.92957780026237e-17
0.603568110306370
1.50690096511644e-17
1.08658472749935e-16
7.57132250704934e-17
2.66708857540784e-17
3.46149910955351e-17
4.60978724678206e-17
1.08662313490113e-16
3.42358702150843e-17
6.83050304959970e-17
3.19996471309376e-17
2.16907081538632e-17
3.86591323728191e-17
3.79905582515998e-17
0.396431889693630
7.91948069773015e-17
4.45074411271270e-17
1.62958265807977e-17
3.82178738490695e-17
6.29223776757741e-17
0.396431889693630
1.67754047209576e-17
9.29887909458497e-17
1.97404623930945e-16
3.21006025529018e-17
1.67710094162830e-17
6.66239520645662e-17
5.10705211487009e-17
6.60990290141418e-17
9.57923943544337e-17
1.63832398168987e-17
1.09271312617687e-16
9.86367617174531e-17
1.04778191828700e-17
1.63328769628357e-17
2.38964338862913e-17
3.31525936867943e-17
1.50611423756745e-17
1.63584208473992e-17
4.77231692759105e-18
1.71376002724474e-17
4.31323742881893e-17
0.396431889693627
1.66301917233621e-17
4.82083728961189e-17
0.396431889693630
0.603568110306370
2.10715955520674e-17
3.13644682835338e-17
3.14812533719443e-17
0.603568110306370
3.14554957117173e-17
2.13533177480005e-17
2.12752992135221e-17
2.22721447422380e-17
1.04619418830474e-16
2.06781467381881e-17
4.48010344135470e-17
3.22580040952438e-16
9.27628888218478e-17
2.72418435850740e-17
5.02352395116210e-16
1.76731781201018e-17
1.94510019414797e-17
1.95654458571480e-17
6.44635719788115e-17
0.396431889693627
8.87190649432377e-18
3.32600042326679e-15
1.43844728919083e-17
1.88259667380649e-17
0.603568110306370
9.09055592297213e-18
7.66497777615146e-17
2.09304785104558e-17
0.603568110306373
3.79279708304661e-17
1.59997709593021e-18

回答 (1 件)

Matt J
Matt J 2021 年 10 月 22 日
There's nothing wrong with post-rounding, however setting lb(i)=ub(i)=0 for the appropriate variables should force them to an exact value of zero.
Of course, since you know the variables are zero, an even better approach would be to not include them in the list of unknowns in the first place. Possibly, quadprog will pre-process the problem this way for you when it sees that lb(i)=ub(i)=0, but I'm not completely sure.

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by