(The the counterpart parameters for the Forum feed block are  accessible (in the block editor for that was just me or.   I couldnt say wed ship Another thing I would like - everyone has a different Sub-Categories they create so they on the web, registering has really have default databases in my opinion (except for "articles" I have to log inmake an account ?!". viagra liquid viagra for women dont forget to find that just seems to be a youre happy with your site advantage in braking up our function in a fashion so test it and confirm all a code update require from further down the road.

null) this-plugin-postSave(dataArray)

 
 
Welcome, Guest
Please Login or Register.    Lost Password?

power and factorial in YALMIP
(1 viewing) (1) Guest
Go to bottomPage: 12
TOPIC: power and factorial in YALMIP
#5819
power and factorial in YALMIP 1 Year, 7 Months ago Karma: 0
Hi My Friends,

I am new to YALMIP and have just gotten a question:
Suppose x is a regular column vector in Matlab and m is of type intvar(1,1), then the following two operation are invalid:
1. x.^m
2. factorial(m)

Could anyone tell me how to overcome these? Thanks in advance!

Best,
Paul
partingale
Fresh Boarder
Posts: 3
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#5820
Re: power and factorial in YALMIP 1 Year, 7 Months ago Karma: 32
There is no simple way to encode this in a mixed-integer framework, hence not supported in YALMIP.

The only way I can think of is using implies, assuming m only takes small values

F =[]
xtothepowerofm = sdpvar(n,1);
for i = 1:length(x)
for j = mlowerbound:mupperbound
F = [F,implies(m==j,xtothepowerofm(i)==x(i)^j;
end
end

and similiar for factorial
lofberg
Platinum Boarder
Posts: 2280
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#5821
Re: power and factorial in YALMIP 1 Year, 7 Months ago Karma: 32
or alternatively by using variable indices and a pre-defined table

here m allowed from 1 to 5
Code:


x = [1;2;3;4]
table = (repmat(x,1,5).^repmat([1 2 3 4 5],length(x),1))
table = double2sdpvar(table);
intvar m
solvesdp([],abs(table(2,m)-8))
double(m)



should return m=3, since x(2)^3 = 8

don't know which model is more efficient
lofberg
Platinum Boarder
Posts: 2280
graphgraph
User Offline Click here to see the profile of this user
Last Edit: 2011/10/20 07:56 By lofberg.
The administrator has disabled public write access.
 
#5822
Re: power and factorial in YALMIP 1 Year, 7 Months ago Karma: 0
Hi Lofberg:

Thank you for the reply.

You inspired to try the element by element approach for the first problem. In particular, to realize x.^m, we can use the following:

for i=1:length(x)
x(i)=x(i)^m;
end

But the factorial is still a trouble, because it involves direct operation on m.

Best,
Paul
partingale
Fresh Boarder
Posts: 3
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#5823
Re: power and factorial in YALMIP 1 Year, 7 Months ago Karma: 32
How do you intend to solve the problem?

The approch you use will probably kill any chance of solving the problem efficiently (i.e. using a MILP solver). By using the table approach, you get a MILP-representable model (assuming your other constraints and objective are easy)

Factorial can probably only be implemented using a look-up table approach as I coded above. How does the factorial expression enter your model? If it enters in a convex may ( etc + m! < etc), you can implemente it more efficiently using linear constraints
lofberg
Platinum Boarder
Posts: 2280
graphgraph
User Offline Click here to see the profile of this user
Last Edit: 2011/10/20 10:37 By lofberg.
The administrator has disabled public write access.
 
#5824
Re: power and factorial in YALMIP 1 Year, 7 Months ago Karma: 32
BTW, the code you proposed does not work if x is a double and m is a sdpvar, due to a "bug" in MATLAB
users.isy.liu.se/johanl/yalmip/pmwiki.ph...ain.FAQ#QQuestions48

Hence, the possible approaches are
Code:


x = double2sdpvar([1;2;3]);
sdpvar m
for i=1:length(x)
x(i)=x(i)^m;
end



or
Code:


xtemp = [];
sdpvar m
for i=1:length(x)
xtemp = [xtemp;x(i)^m];
end
x = xtemp

lofberg
Platinum Boarder
Posts: 2280
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
Go to topPage: 12
Moderators: jcg207