Hi everyone,
I'm struggling to write a set of equations. Suppose I have the vector
N={1 2 3 ... 10}
and I write the loop
for i=1:1:N
fprintf(' + x%d ', i);
end
fprintf(' = 1');
But now I need to write the same equation for all possible subsets of
N, ranging from 2 to 8 elements.
So it can be only elements {1, 2}, {1, 3}, ... {5, 10}, up to all
combinations until 8 elements.
Any ideas of hints are very welcome.
Thnaks
|
|
0
|
|
|
|
Reply
|
leandro.cc (1)
|
4/27/2010 4:36:43 PM |
|
Leandro Callegari Coelho wrote:
> Hi everyone,
>
> I'm struggling to write a set of equations. Suppose I have the vector
> N={1 2 3 ... 10}
> and I write the loop
>
> for i=1:1:N
> fprintf(' + x%d ', i);
> end
> fprintf(' = 1');
>
> But now I need to write the same equation for all possible subsets of
> N, ranging from 2 to 8 elements.
> So it can be only elements {1, 2}, {1, 3}, ... {5, 10}, up to all
> combinations until 8 elements.
>
> Any ideas of hints are very welcome.
Consider the results of the following...
for idx=1:N
nchoosek(1:N,idx)
end
You might find w/ N rather small first more easily enlightening... :)
--
|
|
0
|
|
|
|
Reply
|
dpb
|
4/27/2010 4:47:56 PM
|
|
You need to give an example which doesn't fail. Perhaps a simpler version of your actual problem, with the inputs and outputs shown explicitly, would help.
>> N = {1 2 3 4 5 6 7 8 9 10};
>> for i=1:1:N
fprintf(' + x%d ', i);
end
fprintf(' = 1');
??? Undefined function or method '_colonobj' for input arguments of type 'cell'.
>>
|
|
0
|
|
|
|
Reply
|
Matt
|
4/27/2010 4:55:08 PM
|
|
On Apr 27, 8:55=A0am, "Matt Fig" <spama...@yahoo.com> wrote:
> You need to give an example which doesn't fail. =A0Perhaps a simpler vers=
ion of your actual problem, with the inputs and outputs shown explicitly, w=
ould help.
>
> >> N =3D {1 2 3 4 5 6 7 8 9 10};
> >> for i=3D1:1:N
>
> =A0 =A0fprintf(' + x%d ', i);
> end
> fprintf(' =3D 1');
> ??? Undefined function or method '_colonobj' for input arguments of type =
'cell'.
>
>
Matt, here's a simple version (believe me, the equations I'm trying to
write are much more complex than this).
N=3D5
for i=3D1:1:N
fprintf(' + x%d', i);
end
This will write:
x1 + x2 + x3 + x4 + x5
Now I want something to write approx 2^N equations, the output would
be
x1 + x2
x1 + x3
x1 + x4
x1 + x5
x2 + x3
....
than w/ 3 elements:
x1 + x2 + x3
x1 + x2 + x4
x1 + x2 + x5
....
If N is 10, than I need all possible combinations from 2 to 8
elements(2 to (N-2) elements).
I'll try with dbp's suggestion (thanks!)
Regards
|
|
0
|
|
|
|
Reply
|
Leandro
|
4/27/2010 5:20:44 PM
|
|
Something like this:
N = 10;
for jj = 2:8
T = nchoosek(1:N,jj);
for ii = 1:size(T,1)
fprintf(['x%i',repmat(' + x%i',1,size(T,2)-1),'\n'],T(ii,:))
end
fprintf('\n\n\n')
end
|
|
0
|
|
|
|
Reply
|
Matt
|
4/27/2010 5:34:05 PM
|
|
On Apr 27, 9:34=A0am, "Matt Fig" <spama...@yahoo.com> wrote:
> Something like this:
>
> N =3D 10;
>
> for jj =3D 2:8
> =A0 =A0 T =3D nchoosek(1:N,jj);
>
> =A0 =A0 for ii =3D 1:size(T,1)
> =A0 =A0 =A0 =A0 fprintf(['x%i',repmat(' + x%i',1,size(T,2)-1),'\n'],T(ii,=
:))
> =A0 =A0 end
> =A0 =A0 fprintf('\n\n\n')
> end
Matt, thanks a lot. It works, I just need to adapt it to my equations.
I really appreciate your attention.
|
|
0
|
|
|
|
Reply
|
Leandro
|
4/27/2010 5:52:16 PM
|
|
Leandro Callegari Coelho wrote:
> On Apr 27, 9:34 am, "Matt Fig" <spama...@yahoo.com> wrote:
>> Something like this:
>>
>> N = 10;
>>
>> for jj = 2:8
>> T = nchoosek(1:N,jj);
....
>
> Matt, thanks a lot. It works, I just need to adapt it to my equations.
> I really appreciate your attention.
for jj = 2:8
T = nchoosek(1:N,jj);
looks somehow remarkably similar to dpb's hint to explore
for idx=1:N
nchoosek(1:N,idx)
:)
--
|
|
0
|
|
|
|
Reply
|
dpb
|
4/27/2010 8:25:22 PM
|
|
dpb <none@non.net> wrote in message <hr7hat$7kd$1@news.eternal-september.org>...
> Leandro Callegari Coelho wrote:
> > On Apr 27, 9:34 am, "Matt Fig" <spama...@yahoo.com> wrote:
> >> Something like this:
> >>
> >> N = 10;
> >>
> >> for jj = 2:8
> >> T = nchoosek(1:N,jj);
> ...
> >
> > Matt, thanks a lot. It works, I just need to adapt it to my equations.
> > I really appreciate your attention.
>
> for jj = 2:8
> T = nchoosek(1:N,jj);
>
> looks somehow remarkably similar to dpb's hint to explore
>
> for idx=1:N
> nchoosek(1:N,idx)
>
> :)
>
> --
I went with
N=[1 2 3 4];
len=length(N);
for i =0:1:2^(len)-1
subset=dec2bin(i,len)=='1';
for j= N(subset)
fprintf(' + x%d ', j);
end
fprintf('=1\n');
end
if you don't want the empty set (ie =1) just switch the loop over i to start with 1
I also changed N from a struct to a vector
|
|
0
|
|
|
|
Reply
|
Adam
|
4/27/2010 8:59:07 PM
|
|
Guys, since you're posting here again, I'll ask your help once again.
Turns out the equation I'm trying to write is way too hard to me.
Take a look at the equation here: http://twitpic.com/1iy2bu
Using your ideas I could almost finish the left side.
Explaining from the right to the left:
Big-fancy t can be small, i.e 3
Big-fancy M is what we're using N here, so it can be something like 5.
(for the ones that are curious this equation avoids subtours on a
vehicle routing model)
Anyone with enough time to tackle this?
|
|
0
|
|
|
|
Reply
|
Leandro
|
4/27/2010 9:35:01 PM
|
|
On Apr 27, 1:35=A0pm, Leandro Callegari Coelho <leandro...@gmail.com>
wrote:
> Guys, since you're posting here again, I'll ask your help once again.
> Turns out the equation I'm trying to write is way too hard to me.
>
> Take a look at the equation here:http://twitpic.com/1iy2bu
> Using your ideas I could almost finish the left side.
>
> Explaining from the right to the left:
> Big-fancy t can be small, i.e 3
> Big-fancy M is what we're using N here, so it can be something like 5.
>
> (for the ones that are curious this equation avoids subtours on a
> vehicle routing model)
>
> Anyone with enough time to tackle this?
bump
|
|
0
|
|
|
|
Reply
|
Leandro
|
4/28/2010 12:44:22 PM
|
|
|
9 Replies
352 Views
(page loaded in 0.133 seconds)
Similiar Articles: problem with subsets - comp.soft-sys.matlabHi everyone, I'm struggling to write a set of equations. Suppose I have the vector N={1 2 3 ... 10} and I write the loop for i=1:1:N fpri... Problem Combining 2 PDF Files: Same Subset fonts - comp.text.pdf ...Hello, I had this problem last year and I solved it like this: 1- Use "extract pages" feature in Acrobat 5, to pull out the pages from the chapters that would not ... split the vector in n subvectors - comp.soft-sys.matlabproblem with subsets - comp.soft-sys.matlab split the vector in n subvectors - comp.soft-sys.matlab problem with subsets - comp.soft-sys.matlab Suppose I have the vector ... Substitute font subsets with acrobat - comp.text.pdfProblem Combining 2 PDF Files: Same Subset fonts - comp.text.pdf ... I'd like to know also if, using Acrobat 8, it's possible to change the Font ... poly2mask problem - comp.soft-sys.matlabhi everyone i'm doing poly2mask, but i have some problem. this is the code y ... matlab split the vector in n subvectors - comp.soft-sys.matlab problem with subsets ... Problems with ATI (drivers suxx) - comp.graphics.api.opengl ...Fonts for TV-Program - comp.fonts Problem Combining 2 PDF Files: Same Subset fonts - comp.text.pdf ... Problem Combining 2 ... for text rendering (using ... Report Summary fields show incorrect totals - comp.databases ...The problem is the summary fields are ... report, I do a find on a subset of Jobs.fp5 records, enter > preview mode, and sort by the break field (JobNo). > > The problem is ... How to solve ligatures problem in pdf - comp.text.pdfProblem Combining 2 PDF Files: Same Subset fonts - comp.text.pdf ... How to solve ligatures problem in pdf - comp.text.pdf Problem Combining 2 PDF Files: Same Subset fonts ... Plotting feasible region of a linear programme - comp.soft-sys ...... hadamard]; > vs = Range[8]; > m = mm /@ vs; > sectionAnchors = Subsets[vs ... Grapher (Two Variables) - Hofstra People Enter your linear programming problem (with ... gnuplot's tiny problems - comp.graphics.apps.gnuplotFor the interface I need only a tiny subset of gnuplot. The communication is ... of the functionality I need, I decided to ask about some of the encountered problems. Subset sum problem - Wikipedia, the free encyclopediaIn computer science, the subset sum problem is an important problem in complexity theory and cryptography. The problem is this: given a set of integers, is there a ... Subset Sum Problem -- from Wolfram MathWorldThere are two problems commonly known as the subset sum problem. The first is the problem of finding what subset of a list of integers has a given sum, which is an ... 7/26/2012 10:46:31 PM
|