Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Linear Combination

Subject: Linear Combination

From: je w

Date: 17 Dec, 2008 10:31:03

Message: 1 of 10

Anyone knows how to write a matlab code for linear combination?

Question: a=[43 50 86 93 129]. the linear combination between the elements of a can be expressed by using:
i) simple multiple of preceeding elements; e.g. a(3)=2a(1)
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)

The output of linear combination of the above matrix a should be:

a(2) has no linear combination;

a(3)=2a(1);

a(4)=[a(2)-a(1)]+2a(1);

a(5)=3a(1)and a(5)= [a(3)-a(1)]+2a(1)

note there can be more than one linear combination for each element.

Thank you sooooooooo much!:-)

Subject: Linear Combination

From: Bruno Luong

Date: 17 Dec, 2008 10:49:02

Message: 2 of 10

"je w" <jingyerushisg@yahoo.com.sg> wrote in message <giakd7$ri2$1@fred.mathworks.com>...
> Anyone knows how to write a matlab code for linear combination?
>
> Question: a=[43 50 86 93 129]. the linear combination between the elements of a can be expressed by using:
> i) simple multiple of preceeding elements; e.g. a(3)=2a(1)
> 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)
>
> The output of linear combination of the above matrix a should be:
>
> a(2) has no linear combination;
>
> a(3)=2a(1);
>
> a(4)=[a(2)-a(1)]+2a(1);
>
> a(5)=3a(1)and a(5)= [a(3)-a(1)]+2a(1)
>

Are you restrict to *integer* coefficients only ?

Bruno

Subject: Linear Combination

From: John D'Errico

Date: 17 Dec, 2008 11:47:02

Message: 3 of 10

"je w" <jingyerushisg@yahoo.com.sg> wrote in message <giakd7$ri2$1@fred.mathworks.com>...
> Anyone knows how to write a matlab code for linear combination?
>
> Question: a=[43 50 86 93 129]. the linear combination between the elements of a can be expressed by using:
> i) simple multiple of preceeding elements; e.g. a(3)=2a(1)
> 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)
>
> The output of linear combination of the above matrix a should be:
>
> a(2) has no linear combination;
>
> a(3)=2a(1);
>
> a(4)=[a(2)-a(1)]+2a(1);
>
> a(5)=3a(1)and a(5)= [a(3)-a(1)]+2a(1)
>
> note there can be more than one linear combination for each element.
>
> Thank you sooooooooo much!:-)

Since there will often be infinitely many such
"linear combinations", even if you restrict the
solutions to integer coefficients with either sign,
do you have an infinite amount of time to wait
for the solution?

John

Subject: Linear Combination

From: Roger Stafford

Date: 17 Dec, 2008 21:49:02

Message: 4 of 10

"je w" <jingyerushisg@yahoo.com.sg> wrote in message <giakd7$ri2$1@fred.mathworks.com>...
> Anyone knows how to write a matlab code for linear combination?
> ........

  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.)

Roger Stafford

Subject: Linear Combination

From: je w

Date: 18 Dec, 2008 02:26:02

Message: 5 of 10

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <gibs4e$cgd$1@fred.mathworks.com>...
> "je w" <jingyerushisg@yahoo.com.sg> wrote in message <giakd7$ri2$1@fred.mathworks.com>...
> > Anyone knows how to write a matlab code for linear combination?
> > ........
>
> 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.)
>
> Roger Stafford

Thanks a lot for everyone's suggestions! :-)

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.
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)].

Thank you! :-)

Subject: Linear Combination

From: Roger Stafford

Date: 18 Dec, 2008 03:03:03

Message: 6 of 10

"je w" <wangjing_sg@hotmail.com> wrote in message <giccbq$cnf$1@fred.mathworks.com>...
> ........
> 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.
> .........

  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 positive-valued coefficients in mind when you spoke of "a finite number of combinations"?

Roger Stafford

Subject: Linear Combination

From: John D'Errico

Date: 18 Dec, 2008 04:13:04

Message: 7 of 10

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <giceh7$rtl$1@fred.mathworks.com>...
> "je w" <wangjing_sg@hotmail.com> wrote in message <giccbq$cnf$1@fred.mathworks.com>...
> > ........
> > 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.
> > .........
>
> 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 positive-valued coefficients in mind when you spoke of "a finite number of combinations"?
>
> Roger Stafford

That cannot be, since one of the examples given had
coefficients of both signs. And, yes, Roger was correct.

John

Subject: Linear Combination

From: Bruno Luong

Date: 18 Dec, 2008 06:59:04

Message: 8 of 10

"je w" <wangjing_sg@hotmail.com> wrote in message <giccbq$cnf$1@fred.mathworks.com>...

> Yes both the coefficients for linear combinations and the elements of the array are *integers*;

See this thread, the code is given there:

http://www.mathworks.com/matlabcentral/newsreader/view_thread/172882

> 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.

Even if three elements, the number of solution is either 0 or infinity. What you are expecting falls down.

Bruno

Subject: Linear Combination

From: je w

Date: 18 Dec, 2008 07:59:05

Message: 9 of 10

"John D'Errico" <woodchips@rochester.rr.com> wrote in message <gicikg$5l2$1@fred.mathworks.com>...
> "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <giceh7$rtl$1@fred.mathworks.com>...
> > "je w" <wangjing_sg@hotmail.com> wrote in message <giccbq$cnf$1@fred.mathworks.com>...
> > > ........
> > > 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.
> > > .........
> >
> > 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 positive-valued coefficients in mind when you spoke of "a finite number of combinations"?
> >
> > Roger Stafford
>
> That cannot be, since one of the examples given had
> coefficients of both signs. And, yes, Roger was correct.
>
> John

Let me clarify and give more information:

Actually we want to find whether the successive elements are related to the previous elements, as long as they are related by integer coefficient.

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.

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.

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.

Thank you for your kind help.

Subject: Linear Combination

From: Bruno Luong

Date: 18 Dec, 2008 09:58:03

Message: 10 of 10

"je w" <wangjing_sg@hotmail.com> wrote in message <gicvs9$1g8$1@fred.mathworks.com>...
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.
>

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.

Bruno

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us