473,404 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Constrained Optimization Problem in C


The task is to solve a constrained optimization problem in C.
Computational
Time is of high priority. One approach can be to use ready functions
in a "free ware" Optimization Library (if available). If any one of
you have any idea about such library please inform me. I am dealing
with Constrained Optimization for the first time so please guide me
How I should solve this problem. I will appreciate suggestions from
you.

Find values of x that minimize f=-x1*x2*x3 and subject to the
constraints:

x1+2*x2+2*x3>0
x1+2*x2+2*x3<72
x2=10
In Matlab it can be solved by:

x0 = [10; 10; 10]; % Starting guess at the solution

A=[]; b=[]; Aeq=[]; beq=[]; lb=[]; ub=[];

[x,fval] = fmincon(@myfun,x0,A,b,Aeq,beq,lb,ub,@(x)constr(x))
%myfun

function f = myfun(x)

f = -x(1)* x(2)* x(3); %f=-x1*x2*x3
%constr

function [c,ceq]=constr(x)

c(1)=0-(x(1)+2*x(2)+2*x(3)); %x1+2*x2+2*x3>0

c(2)=x(1)+2*x(2)+2*x(3)-72; %x1+2*x2+2*x3<72

ceq(1)=x(2)-10; %x2=10

Hoping to hear from you guys !!!!

--
/BR
Hassan
Jan 2 '08 #1
2 2603
On Jan 2, 1:44*pm, Explore_Imagination <Mr.HassanShab...@gmail.com>
wrote:
The task is to solve a constrained optimization problem in C.
Computational
Time is of high priority. One approach can be to use ready functions
in a "free ware" Optimization Library (if available). If any one of
you have any idea about such library please inform me. I am dealing
with Constrained Optimization for the first time so please guide me
How I should solve this problem. I will appreciate suggestions from
you.

Find values of x that minimize *f=-x1*x2*x3 *and subject to the
constraints:

x1+2*x2+2*x3>0
x1+2*x2+2*x3<72
x2=10

In Matlab it can be solved by:

x0 = [10; 10; 10]; * *% Starting guess at the solution

A=[]; *b=[]; *Aeq=[]; beq=[]; *lb=[]; *ub=[];

[x,fval] = fmincon(@myfun,x0,A,b,Aeq,beq,lb,ub,@(x)constr(x))

%myfun

function f = myfun(x)

f = -x(1)* x(2)* x(3); * * * *%f=-x1*x2*x3

%constr

function [c,ceq]=constr(x)

c(1)=0-(x(1)+2*x(2)+2*x(3)); * %x1+2*x2+2*x3>0

c(2)=x(1)+2*x(2)+2*x(3)-72; * * %x1+2*x2+2*x3<72

ceq(1)=x(2)-10; * * * * * * * * %x2=10

Hoping to *hear from you guys !!!!
Go here:
http://plato.asu.edu/cgi-bin/htsearch
Type in search window "constrained optimization problem"

You probably wanted news:sci.math.num-analysis because your question
is not about the C language at all.

Jan 2 '08 #2
Explore_Imagination wrote:
The task is to solve a constrained optimization problem in C.
Computational
Time is of high priority. One approach can be to use ready functions
in a "free ware" Optimization Library (if available). If any one of
you have any idea about such library please inform me. I am dealing
with Constrained Optimization for the first time so please guide me
How I should solve this problem. I will appreciate suggestions from
you.

Find values of x that minimize f=-x1*x2*x3 and subject to the
constraints:

x1+2*x2+2*x3>0
x1+2*x2+2*x3<72
x2=10
In Matlab it can be solved by:
[...]
With pencil and paper it can be solved in less time
than it took to compose the query. There are only two
variables, the objective function is the negated product
of those two variables, and the feasible region is bounded
by two parallel lines. By inspection, the minimum must
occur when the two variables have the same sign (the point
(0,0) is in the feasible region, so the minimum cannot be
positive). The minimum therefore occurs somewhere on the
boundary of the butterfly-shaped region consisting of a
triangle in each of the first and third quadrants. It
cannot be anywhere along the axes (the product there is
zero), so it must be somewhere on one of the hypotenuses.
The first-quadrant triangle's hypotenuse is farther from
the origin, so the product there must be larger than that
along the third-quarter hypotenuse. Time for a tiny bit of
calculus to find one derivative, and Bingo!

Are you killing canaries with cannon, or massacring
magpies with Matlab?

--
Eric Sosman
es*****@ieee-dot-org.invalid
Jan 3 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Rune | last post by:
Is it best to use double quotes and let PHP expand variables inside strings, or is it faster to do the string manipulation yourself manually? Which is quicker? 1) $insert = 'To Be';...
5
by: wkaras | last post by:
I've compiled this code: const int x0 = 10; const int x1 = 20; const int x2 = 30; int x = { x2, x0, x1 }; struct Y {
7
by: laniik | last post by:
Hi, I am looking for a way to do nonlinear minimization in c++ (c is acceptable also) with constraints (a la minimize f() with parameters x,y such that x+y<1) or somthing.. I was wondering if...
3
by: amitsoni.1984 | last post by:
Hi, I need to do a quadratic optimization problem in python where the constraints are quadratic and objective function is linear. What are the possible choices to do this. Thanks Amit
4
by: Massimo | last post by:
I have a very very strange situation with a particular application and sql server 2005 enterprise. This application combines numerical data from multiple tables. User can make query over this...
6
by: Explore_Imagination | last post by:
The task is to solve a constrained optimization problem in C/C++. Computational Time is of high priority. One approach can be to use ready functions in a "free ware" Optimization Library (if...
2
by: navon2 | last post by:
Hi I need to find x that will minimize Ax-b=0, under the inequality constraints Cx<d. Actually the constraints in my problem are only upper and lower bounds to x values. x is 4x1 vector, A is...
20
by: Ravikiran | last post by:
Hi Friends, I wanted know about whatt is ment by zero optimization and sign optimization and its differences.... Thank you...
2
by: Sammo | last post by:
Hi all, I'm new to Python (and to coding in general). If anyone can help out with the problem below or point me in the right direction I'd really appreciate it. I have a noisy dataset through...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.