Matlab optimization - variables to satisfy L1 norm (2024)

46 views (last 30 days)

Show older comments

Simon Philipp Hehenberger on 10 Jul 2024 at 8:29

  • Link

    Direct link to this question

    https://webchat.mathworks.com/matlabcentral/answers/2136078-matlab-optimization-variables-to-satisfy-l1-norm

  • Link

    Direct link to this question

    https://webchat.mathworks.com/matlabcentral/answers/2136078-matlab-optimization-variables-to-satisfy-l1-norm

Commented: Manikanta Aditya on 10 Jul 2024 at 9:58

Open in MATLAB Online

Hi,

I am trying to set up an optimization problem, the variables of my problem are stored in vector x, which is of length 4.

How do I constrain my optimization such that the first three elements in my vector x satisfy the L1 norm.

In my current setup i am using fmincon with the following code:

x0=[A_init'; th_init];

opt=optimoptions('fmincon','MaxFunctionEvaluations',1e5,'Display','iter','MaxIterations',1e3,...

'Algorithm','sqp','FiniteDifferenceStepSize',1e-6,'DiffMinChange',0.00051,'DiffMaxChange',0.2);

[x,fval,exitflag,output]=fmincon(@(x)costFunction_es_sa(x,a,N,epRm,epR_target),x0,[],[],[],[],[0.1 0.1 0.1 0.01]',[1 1 1 0.61]',[],opt)

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

Answers (2)

Manikanta Aditya on 10 Jul 2024 at 8:39

  • Link

    Direct link to this answer

    https://webchat.mathworks.com/matlabcentral/answers/2136078-matlab-optimization-variables-to-satisfy-l1-norm#answer_1483683

  • Link

    Direct link to this answer

    https://webchat.mathworks.com/matlabcentral/answers/2136078-matlab-optimization-variables-to-satisfy-l1-norm#answer_1483683

To constrain the first three elements of your vector ( x ) to satisfy the ( L1 ) norm in an optimization problem using fmincon in MATLAB, you can add a nonlinear constraint function.

% Initial guess

x0 = [A_init'; th_init];

% Optimization options

opt = optimoptions('fmincon', 'MaxFunctionEvaluations', 1e5, 'Display', 'iter', ...

'MaxIterations', 1e3, 'Algorithm', 'sqp', 'FiniteDifferenceStepSize', 1e-6, ...

'DiffMinChange', 0.00051, 'DiffMaxChange', 0.2);

% Nonlinear constraint function

nonlcon = @(x) l1NormConstraint(x);

% Call fmincon with the nonlinear constraint

[x, fval, exitflag, output] = fmincon(@(x) costFunction_es_sa(x, a, N, epRm, epR_target), ...

x0, [], [], [], [], [0.1 0.1 0.1 0.01]', [1 1 1 0.61]', nonlcon, opt);

% Nonlinear constraint function definition

function [c, ceq] = l1NormConstraint(x)

% L1 norm constraint for the first three elements of x

c = sum(abs(x(1:3))) - c_bound; % c_bound is your desired bound for the L1 norm

ceq = []; % No equality constraints

end

5 Comments

Show 3 older commentsHide 3 older comments

Simon Philipp Hehenberger on 10 Jul 2024 at 9:14

Direct link to this comment

https://webchat.mathworks.com/matlabcentral/answers/2136078-matlab-optimization-variables-to-satisfy-l1-norm#comment_3207523

  • Link

    Direct link to this comment

    https://webchat.mathworks.com/matlabcentral/answers/2136078-matlab-optimization-variables-to-satisfy-l1-norm#comment_3207523

Open in MATLAB Online

Thank you for your answer.

In fact I want the l1 norm of the first three values to be exactly 1.

So I have set up the nonlinear constraint function like this:

function [c,ceq] = l1NormConstraint(x)

% L1 norm constraint for the first three elements of x

c=[];

ceq = sum(abs(x(1:3)))-1;

end

But I am getting the error: "Failure in initial nonlinear constraint function evaluation. FMINCON cannot continue." What am I missing

Aquatris on 10 Jul 2024 at 9:25

Direct link to this comment

https://webchat.mathworks.com/matlabcentral/answers/2136078-matlab-optimization-variables-to-satisfy-l1-norm#comment_3207543

  • Link

    Direct link to this comment

    https://webchat.mathworks.com/matlabcentral/answers/2136078-matlab-optimization-variables-to-satisfy-l1-norm#comment_3207543

Edited: Aquatris on 10 Jul 2024 at 9:26

Probably your x0 does not satisfy the L1 norm condition. You need to provide more info for us to be helpful.

Manikanta Aditya on 10 Jul 2024 at 9:30

Direct link to this comment

https://webchat.mathworks.com/matlabcentral/answers/2136078-matlab-optimization-variables-to-satisfy-l1-norm#comment_3207553

  • Link

    Direct link to this comment

    https://webchat.mathworks.com/matlabcentral/answers/2136078-matlab-optimization-variables-to-satisfy-l1-norm#comment_3207553

+1 to what @Aquatris mentioned.

Also refer this MATLAB Answer to know more about the error:

  • https://www.mathworks.com/matlabcentral/answers/694040-failure-in-initial-nonlinear-constraint-function-evaluation-fmincon-cannot-continue

Simon Philipp Hehenberger on 10 Jul 2024 at 9:43

Direct link to this comment

https://webchat.mathworks.com/matlabcentral/answers/2136078-matlab-optimization-variables-to-satisfy-l1-norm#comment_3207563

  • Link

    Direct link to this comment

    https://webchat.mathworks.com/matlabcentral/answers/2136078-matlab-optimization-variables-to-satisfy-l1-norm#comment_3207563

Initial condition not satisfying the nonlinear constraint was indeed the issue.

Thanks alot for your help @Aquatris and @Manikanta Aditya

Manikanta Aditya on 10 Jul 2024 at 9:58

Direct link to this comment

https://webchat.mathworks.com/matlabcentral/answers/2136078-matlab-optimization-variables-to-satisfy-l1-norm#comment_3207593

  • Link

    Direct link to this comment

    https://webchat.mathworks.com/matlabcentral/answers/2136078-matlab-optimization-variables-to-satisfy-l1-norm#comment_3207593

Thanks for informing @Simon Philipp Hehenberger

Sign in to comment.

Aquatris on 10 Jul 2024 at 8:45

  • Link

    Direct link to this answer

    https://webchat.mathworks.com/matlabcentral/answers/2136078-matlab-optimization-variables-to-satisfy-l1-norm#answer_1483688

  • Link

    Direct link to this answer

    https://webchat.mathworks.com/matlabcentral/answers/2136078-matlab-optimization-variables-to-satisfy-l1-norm#answer_1483688

Edited: Aquatris on 10 Jul 2024 at 8:45

Open in MATLAB Online

You create a nonlinear constraint functio and give it as an argument to the fmincon.

[x,fval,exitflag,output]=fmincon(@(x)costFunction_es_sa(x,a,N,epRm,epR_target),x0,...

[],[],[],[],[0.1 0.1 0.1 0.01]',[1 1 1 0.61]',@normL1,opt)

function y = normL1(x); %fmincon will try to satisfy myFun(x)<=0

y = sum(abs(x(1:3))) - 5; % want it to be less than 5 for instance

end

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

See Also

Categories

Mathematics and OptimizationOptimization ToolboxOptimization ResultsSolver Outputs and Iterative Display

Find more on Solver Outputs and Iterative Display in Help Center and File Exchange

Tags

  • optimization
  • fmincon

Community Treasure Hunt

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

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


Matlab optimization - variables to satisfy L1 norm (9)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

Matlab optimization - variables to satisfy L1 norm (2024)
Top Articles
2016 Audi A3 Sedan S LINE S LINE for sale - Palm Desert, CA - craigslist
2015 Jeep Grand Cherokee Overland for sale - Akron, OH - craigslist
Use Copilot in Microsoft Teams meetings
Woodward Avenue (M-1) - Automotive Heritage Trail - National Scenic Byway Foundation
No Limit Telegram Channel
Napa Autocare Locator
Mail Healthcare Uiowa
Skip The Games Norfolk Virginia
Evita Role Wsj Crossword Clue
Scentsy Dashboard Log In
8 Ways to Make a Friend Feel Special on Valentine's Day
Lonadine
Conan Exiles Colored Crystal
Google Flights Missoula
Vintage Stock Edmond Ok
Aris Rachevsky Harvard
Huntersville Town Billboards
Ratchet & Clank Future: Tools of Destruction
The Largest Banks - ​​How to Transfer Money With Only Card Number and CVV (2024)
Azur Lane High Efficiency Combat Logistics Plan
The EyeDoctors Optometrists, 1835 NW Topeka Blvd, Topeka, KS 66608, US - MapQuest
Parkeren Emmen | Reserveren vanaf €9,25 per dag | Q-Park
Jesus Revolution Showtimes Near Regal Stonecrest
SOGo Groupware - Rechenzentrum Universität Osnabrück
Radical Red Ability Pill
Pixel Combat Unblocked
Log in to your MyChart account
Taylored Services Hardeeville Sc
Mawal Gameroom Download
R/Mp5
Shauna's Art Studio Laurel Mississippi
DIY Building Plans for a Picnic Table
Advance Auto Parts Stock Price | AAP Stock Quote, News, and History | Markets Insider
Moonrise Time Tonight Near Me
Http://N14.Ultipro.com
P3P Orthrus With Dodge Slash
Rust Belt Revival Auctions
Mega Millions Lottery - Winning Numbers & Results
Ny Post Front Page Cover Today
Wo ein Pfand ist, ist auch Einweg
60 X 60 Christmas Tablecloths
877-552-2666
60 Days From August 16
10 Best Tips To Implement Successful App Store Optimization in 2024
Oak Hill, Blue Owl Lead Record Finastra Private Credit Loan
Minute Clinic Mooresville Nc
Edt National Board
Houston Primary Care Byron Ga
Ubg98.Github.io Unblocked
Fahrpläne, Preise und Anbieter von Bookaway
Att Corporate Store Location
Affidea ExpressCare - Affidea Ireland
Latest Posts
Article information

Author: Annamae Dooley

Last Updated:

Views: 5355

Rating: 4.4 / 5 (65 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Annamae Dooley

Birthday: 2001-07-26

Address: 9687 Tambra Meadow, Bradleyhaven, TN 53219

Phone: +9316045904039

Job: Future Coordinator

Hobby: Archery, Couponing, Poi, Kite flying, Knitting, Rappelling, Baseball

Introduction: My name is Annamae Dooley, I am a witty, quaint, lovely, clever, rich, sparkling, powerful person who loves writing and wants to share my knowledge and understanding with you.