http://www.mathworks.com/matlabcentral/newsreader/view_thread/241182
MATLAB Central Newsreader  Linear Combination
Feed for thread: Linear Combination
enus
©19942014 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Wed, 17 Dec 2008 10:31:03 +0000
Linear Combination
http://www.mathworks.com/matlabcentral/newsreader/view_thread/241182#617535
je w
Anyone knows how to write a matlab code for linear combination?<br>
<br>
Question: a=[43 50 86 93 129]. the linear combination between the elements of a can be expressed by using:<br>
i) simple multiple of preceeding elements; e.g. a(3)=2a(1) <br>
ii) a multiple of a difference between two preceeding elements, added to a multiple of another preceeding elements; e.g. a(4)=[a(2)a(1)]+2a(1)<br>
<br>
The output of linear combination of the above matrix a should be:<br>
<br>
a(2) has no linear combination;<br>
<br>
a(3)=2a(1);<br>
<br>
a(4)=[a(2)a(1)]+2a(1);<br>
<br>
a(5)=3a(1)and a(5)= [a(3)a(1)]+2a(1)<br>
<br>
note there can be more than one linear combination for each element.<br>
<br>
Thank you sooooooooo much!:)

Wed, 17 Dec 2008 10:49:02 +0000
Re: Linear Combination
http://www.mathworks.com/matlabcentral/newsreader/view_thread/241182#617536
Bruno Luong
"je w" <jingyerushisg@yahoo.com.sg> wrote in message <giakd7$ri2$1@fred.mathworks.com>...<br>
> Anyone knows how to write a matlab code for linear combination?<br>
> <br>
> Question: a=[43 50 86 93 129]. the linear combination between the elements of a can be expressed by using:<br>
> i) simple multiple of preceeding elements; e.g. a(3)=2a(1) <br>
> ii) a multiple of a difference between two preceeding elements, added to a multiple of another preceeding elements; e.g. a(4)=[a(2)a(1)]+2a(1)<br>
> <br>
> The output of linear combination of the above matrix a should be:<br>
> <br>
> a(2) has no linear combination;<br>
> <br>
> a(3)=2a(1);<br>
> <br>
> a(4)=[a(2)a(1)]+2a(1);<br>
> <br>
> a(5)=3a(1)and a(5)= [a(3)a(1)]+2a(1)<br>
> <br>
<br>
Are you restrict to *integer* coefficients only ?<br>
<br>
Bruno

Wed, 17 Dec 2008 11:47:02 +0000
Re: Linear Combination
http://www.mathworks.com/matlabcentral/newsreader/view_thread/241182#617545
John D'Errico
"je w" <jingyerushisg@yahoo.com.sg> wrote in message <giakd7$ri2$1@fred.mathworks.com>...<br>
> Anyone knows how to write a matlab code for linear combination?<br>
> <br>
> Question: a=[43 50 86 93 129]. the linear combination between the elements of a can be expressed by using:<br>
> i) simple multiple of preceeding elements; e.g. a(3)=2a(1) <br>
> ii) a multiple of a difference between two preceeding elements, added to a multiple of another preceeding elements; e.g. a(4)=[a(2)a(1)]+2a(1)<br>
> <br>
> The output of linear combination of the above matrix a should be:<br>
> <br>
> a(2) has no linear combination;<br>
> <br>
> a(3)=2a(1);<br>
> <br>
> a(4)=[a(2)a(1)]+2a(1);<br>
> <br>
> a(5)=3a(1)and a(5)= [a(3)a(1)]+2a(1)<br>
> <br>
> note there can be more than one linear combination for each element.<br>
> <br>
> Thank you sooooooooo much!:)<br>
<br>
Since there will often be infinitely many such<br>
"linear combinations", even if you restrict the<br>
solutions to integer coefficients with either sign,<br>
do you have an infinite amount of time to wait<br>
for the solution?<br>
<br>
John

Wed, 17 Dec 2008 21:49:02 +0000
Re: Linear Combination
http://www.mathworks.com/matlabcentral/newsreader/view_thread/241182#617682
Roger Stafford
"je w" <jingyerushisg@yahoo.com.sg> wrote in message <giakd7$ri2$1@fred.mathworks.com>...<br>
> Anyone knows how to write a matlab code for linear combination?<br>
> ........<br>
<br>
I will give only this hint: make use of matlab's 'gcd' function with all three output arguments. (I assume the "multiples" referred to are to be integral multiples and that the elements of array 'a' are also integers.)<br>
<br>
Roger Stafford

Thu, 18 Dec 2008 02:26:02 +0000
Re: Linear Combination
http://www.mathworks.com/matlabcentral/newsreader/view_thread/241182#617703
je w
"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <gibs4e$cgd$1@fred.mathworks.com>...<br>
> "je w" <jingyerushisg@yahoo.com.sg> wrote in message <giakd7$ri2$1@fred.mathworks.com>...<br>
> > Anyone knows how to write a matlab code for linear combination?<br>
> > ........<br>
> <br>
> I will give only this hint: make use of matlab's 'gcd' function with all three output arguments. (I assume the "multiples" referred to are to be integral multiples and that the elements of array 'a' are also integers.)<br>
> <br>
> Roger Stafford<br>
<br>
Thanks a lot for everyone's suggestions! :)<br>
<br>
Yes both the coefficients for linear combinations and the elements of the array are *integers*; however, we are limiting the array to around 9 elements at most (the example array has 5 elements) in this case, hence, we are expecting a finite number of combinations. <br>
Moreover, the linear combination can be approximated. For example, if the elements are a(1)=43 and a(3)=87 [instead of a(1)=43 and a(3)=86, as stated in the example], we can still consider 87 to be approximately two times of 43. [i.e. a(3)=2a(1)].<br>
<br>
Thank you! :)

Thu, 18 Dec 2008 03:03:03 +0000
Re: Linear Combination
http://www.mathworks.com/matlabcentral/newsreader/view_thread/241182#617705
Roger Stafford
"je w" <wangjing_sg@hotmail.com> wrote in message <giccbq$cnf$1@fred.mathworks.com>...<br>
> ........<br>
> Yes both the coefficients for linear combinations and the elements of the array are *integers*; however, we are limiting the array to around 9 elements at most (the example array has 5 elements) in this case, hence, we are expecting a finite number of combinations. <br>
> .........<br>
<br>
I believe when John said "infinitely many such linear combinations" he was referring to the fact that if you allow your integer coefficients to have either sign (as he stated,) then any given linear combination of two terms can be replaced by infinitely many other possible combinations of the same two values. For example, suppose your two values are 15 and 24 and you are looking for a linear combination of them such that c1*15+c2*24 = 93. One solution is c1 = 3 and c3 = 2. However another is c1 = 5 and c2 = 7. Yet another is c1 = 13 and c3 = 12, and there are infinitely more that follow this same pattern, c1 dropping or increasing by 8's and c2 changing in the opposite direction by 5's. Is it possible you had only positivevalued coefficients in mind when you spoke of "a finite number of combinations"?<br>
<br>
Roger Stafford

Thu, 18 Dec 2008 04:13:04 +0000
Re: Linear Combination
http://www.mathworks.com/matlabcentral/newsreader/view_thread/241182#617715
John D'Errico
"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <giceh7$rtl$1@fred.mathworks.com>...<br>
> "je w" <wangjing_sg@hotmail.com> wrote in message <giccbq$cnf$1@fred.mathworks.com>...<br>
> > ........<br>
> > Yes both the coefficients for linear combinations and the elements of the array are *integers*; however, we are limiting the array to around 9 elements at most (the example array has 5 elements) in this case, hence, we are expecting a finite number of combinations. <br>
> > .........<br>
> <br>
> I believe when John said "infinitely many such linear combinations" he was referring to the fact that if you allow your integer coefficients to have either sign (as he stated,) then any given linear combination of two terms can be replaced by infinitely many other possible combinations of the same two values. For example, suppose your two values are 15 and 24 and you are looking for a linear combination of them such that c1*15+c2*24 = 93. One solution is c1 = 3 and c3 = 2. However another is c1 = 5 and c2 = 7. Yet another is c1 = 13 and c3 = 12, and there are infinitely more that follow this same pattern, c1 dropping or increasing by 8's and c2 changing in the opposite direction by 5's. Is it possible you had only positivevalued coefficients in mind when you spoke of "a finite number of combinations"?<br>
> <br>
> Roger Stafford<br>
<br>
That cannot be, since one of the examples given had<br>
coefficients of both signs. And, yes, Roger was correct.<br>
<br>
John

Thu, 18 Dec 2008 06:59:04 +0000
Re: Linear Combination
http://www.mathworks.com/matlabcentral/newsreader/view_thread/241182#617734
Bruno Luong
"je w" <wangjing_sg@hotmail.com> wrote in message <giccbq$cnf$1@fred.mathworks.com>...<br>
<br>
> Yes both the coefficients for linear combinations and the elements of the array are *integers*;<br>
<br>
See this thread, the code is given there:<br>
<br>
<a href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/172882">http://www.mathworks.com/matlabcentral/newsreader/view_thread/172882</a><br>
<br>
> however, we are limiting the array to around 9 elements at most (the example array has 5 elements) in this case, hence, we are expecting a finite number of combinations. <br>
<br>
Even if three elements, the number of solution is either 0 or infinity. What you are expecting falls down.<br>
<br>
Bruno

Thu, 18 Dec 2008 07:59:05 +0000
Re: Linear Combination
http://www.mathworks.com/matlabcentral/newsreader/view_thread/241182#617739
je w
"John D'Errico" <woodchips@rochester.rr.com> wrote in message <gicikg$5l2$1@fred.mathworks.com>...<br>
> "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <giceh7$rtl$1@fred.mathworks.com>...<br>
> > "je w" <wangjing_sg@hotmail.com> wrote in message <giccbq$cnf$1@fred.mathworks.com>...<br>
> > > ........<br>
> > > Yes both the coefficients for linear combinations and the elements of the array are *integers*; however, we are limiting the array to around 9 elements at most (the example array has 5 elements) in this case, hence, we are expecting a finite number of combinations. <br>
> > > .........<br>
> > <br>
> > I believe when John said "infinitely many such linear combinations" he was referring to the fact that if you allow your integer coefficients to have either sign (as he stated,) then any given linear combination of two terms can be replaced by infinitely many other possible combinations of the same two values. For example, suppose your two values are 15 and 24 and you are looking for a linear combination of them such that c1*15+c2*24 = 93. One solution is c1 = 3 and c3 = 2. However another is c1 = 5 and c2 = 7. Yet another is c1 = 13 and c3 = 12, and there are infinitely more that follow this same pattern, c1 dropping or increasing by 8's and c2 changing in the opposite direction by 5's. Is it possible you had only positivevalued coefficients in mind when you spoke of "a finite number of combinations"?<br>
> > <br>
> > Roger Stafford<br>
> <br>
> That cannot be, since one of the examples given had<br>
> coefficients of both signs. And, yes, Roger was correct.<br>
> <br>
> John<br>
<br>
Let me clarify and give more information:<br>
<br>
Actually we want to find whether the successive elements are related to the previous elements, as long as they are related by integer coefficient.<br>
<br>
Although there can be infinite possibilities for c1 & c2 (as stated by Roger & John), it is sufficient to determine that 15 and 24 are linearly related to 93 by knowing merely 1 pair of c1 and c2 value. <br>
<br>
We are not concerned with how many possible pairs of c1 and c2 there are, nor their exact values. We only need to know if 15 and 24 will be linearly related to 93.<br>
<br>
In addition, the linear combination may be formed with more than 2 preceeding elements. For example, a possible combination could be a(x)=c1*a(i)+c2*a(j)+c3*a(k), where a(i), a(j) & a(k) are the preceeding elements of a(x) in the array. We also want to know if such relationship exists.<br>
<br>
Thank you for your kind help.

Thu, 18 Dec 2008 09:58:03 +0000
Re: Linear Combination
http://www.mathworks.com/matlabcentral/newsreader/view_thread/241182#617762
Bruno Luong
"je w" <wangjing_sg@hotmail.com> wrote in message <gicvs9$1g8$1@fred.mathworks.com>...<br>
a(x)=c1*a(i)+c2*a(j)+c3*a(k), where a(i), a(j) & a(k) are the preceeding elements of a(x) in the array. We also want to know if such relationship exists.<br>
> <br>
<br>
This problem is no more than figure out where as a(x) is divisible by the gcd of {a(i), a(j) and a(k)}. Case closes.<br>
<br>
Bruno