Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: matrix problem

Subject: matrix problem

From: boguS

Date: 27 Jun, 2008 15:18:20

Message: 1 of 11

For two known matrices [k] and [k1] I need to solve <lambda> from Eq:

[k1]=lambda*[k]

Subject: Re: matrix problem

From: boguS

Date: 27 Jun, 2008 15:19:23

Message: 2 of 11

On 27 Iun, 18:18, boguS <bteod...@gmail.com> wrote:
> For two known matrices [k] and [k1] I need to solve <lambda> from Eq:
>
> [k1]=lambda*[k]

<lambda> is scalar.

Subject: Re: matrix problem

From: Ian Clarkson

Date: 27 Jun, 2008 16:29:03

Message: 3 of 11

boguS <bteodoru@gmail.com> wrote in message
<f9d38db3-ae05-4620-a991-46f61d70453c@t54g2000hsg.googlegroups.com>...
> On 27 Iun, 18:18, boguS <bteod...@gmail.com> wrote:
> > For two known matrices [k] and [k1] I need to solve
<lambda> from Eq:
> >
> > [k1]=lambda*[k]
>
> <lambda> is scalar.

Uhh, can't you just divide any element of k1 by the
corresponding element in k? Assuming the elements aren't
zero, that is...

Subject: Re: matrix problem

From: boguS

Date: 27 Jun, 2008 17:08:33

Message: 4 of 11

On 27 Iun, 19:29, "Ian Clarkson" <ovoidkumq...@hotmail.com> wrote:
> boguS <bteod...@gmail.com> wrote in message
>
> <f9d38db3-ae05-4620-a991-46f61d704...@t54g2000hsg.googlegroups.com>...
>
> > On 27 Iun, 18:18, boguS <bteod...@gmail.com> wrote:
> > > For two known matrices [k] and [k1] I need to solve
> <lambda> from Eq:
>
> > > [k1]=lambda*[k]
>
> > <lambda> is scalar.
>
> Uhh, can't you just divide any element of k1 by the
> corresponding element in k? Assuming the elements aren't
> zero, that is...

No, it's not so simple...because I need to write the known [k1] matrix
in such way that it must be <lambda*[k]> were [k] is just a (known)
matrix.

Subject: Re: matrix problem

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 27 Jun, 2008 17:27:33

Message: 5 of 11

In article <7973ad19-75f0-4c31-8f1e-c786818e1e63@z72g2000hsb.googlegroups.com>,
boguS <bteodoru@gmail.com> wrote:
>On 27 Iun, 19:29, "Ian Clarkson" <ovoidkumq...@hotmail.com> wrote:
>> boguS <bteod...@gmail.com> wrote in message

>> <f9d38db3-ae05-4620-a991-46f61d704...@t54g2000hsg.googlegroups.com>...

>> > On 27 Iun, 18:18, boguS <bteod...@gmail.com> wrote:
>> > > For two known matrices [k] and [k1] I need to solve
>> <lambda> from Eq:

>> > > [k1]=lambda*[k]

>> > <lambda> is scalar.

>> Uhh, can't you just divide any element of k1 by the
>> corresponding element in k? Assuming the elements aren't
>> zero, that is...

>No, it's not so simple...because I need to write the known [k1] matrix
>in such way that it must be <lambda*[k]> were [k] is just a (known)
>matrix.

Could you give an example? With the way you have stated your problem,
Ian's response appears correct to me.

Is the following code not an implementation of the definition
of lambda (a scalar) times k (a matrix) ?

k2 = zeros(size(k));
for idx1 = 1:size(k,1)
  for idx2 = 1:size(k,2)
    k2(i,j) = lambda * k(idx1,idx2);
  end
end

If I haven't forgotten my linear algebra too badly, then that
would mean that k1 would have to be the same size as k, and
that L = k1 ./ k would have to be a matrix with all entries equal
to lambda (except for those entries where k was 0.) So dividing
any one k1 entry by its corresponding non-zero k entry would
recover lambda.
--
  "This quitting thing, it's a hard habit to break once you start."
                                              -- Walter Matthau

Subject: Re: matrix problem

From: Roger Stafford

Date: 27 Jun, 2008 17:45:05

Message: 6 of 11

boguS <bteodoru@gmail.com> wrote in message
<7973ad19-75f0-4c31-8f1e-
c786818e1e63@z72g2000hsb.googlegroups.com>...
> No, it's not so simple...because I need to write the known [k1] matrix
> in such way that it must be <lambda*[k]> were [k] is just a (known)
> matrix.

  Well, you can perform some fancy manipulations like this:

 a = trace(k'*k);
 b = trace(k'*k1);
 c = trace(k1'*k1);
 lambda = b/a;

  Then if lambda^2*a + 2*lambda*b + c is equal to zero, you have your solution.
Otherwise, there can be no exact solution, but this lambda does give the least
squares approximation of lambda*k-k1 to zero.

Roger Stafford

Subject: Re: matrix problem

From: John D'Errico

Date: 27 Jun, 2008 17:55:05

Message: 7 of 11

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in
message <g438v1$keu$1@fred.mathworks.com>...
> boguS <bteodoru@gmail.com> wrote in message
> <7973ad19-75f0-4c31-8f1e-
> c786818e1e63@z72g2000hsb.googlegroups.com>...
> > No, it's not so simple...because I need to write the known [k1] matrix
> > in such way that it must be <lambda*[k]> were [k] is just a (known)
> > matrix.
>
> Well, you can perform some fancy manipulations like this:
>
> a = trace(k'*k);
> b = trace(k'*k1);
> c = trace(k1'*k1);
> lambda = b/a;
>
> Then if lambda^2*a + 2*lambda*b + c is equal to zero, you have your
solution.
> Otherwise, there can be no exact solution, but this lambda does give the
least
> squares approximation of lambda*k-k1 to zero.
>
> Roger Stafford
>

Why so much effort? The least squares solution
is just this:

lambda = k(:)\k1(:);

John

Subject: Re: matrix problem

From: boguS

Date: 27 Jun, 2008 18:03:00

Message: 8 of 11

On 27 Iun, 20:27, rober...@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote:
> In article <7973ad19-75f0-4c31-8f1e-c786818e1...@z72g2000hsb.googlegroups.com>,
>
> boguS <bteod...@gmail.com> wrote:
> >On 27 Iun, 19:29, "Ian Clarkson" <ovoidkumq...@hotmail.com> wrote:
> >> boguS <bteod...@gmail.com> wrote in message
> >> <f9d38db3-ae05-4620-a991-46f61d704...@t54g2000hsg.googlegroups.com>...
> >> > On 27 Iun, 18:18, boguS <bteod...@gmail.com> wrote:
> >> > > For two known matrices [k] and [k1] I need to solve
> >> <lambda> from Eq:
> >> > > [k1]=lambda*[k]
> >> > <lambda> is scalar.
> >> Uhh, can't you just divide any element of k1 by the
> >> corresponding element in k? Assuming the elements aren't
> >> zero, that is...
> >No, it's not so simple...because I need to write the known [k1] matrix
> >in such way that it must be <lambda*[k]> were [k] is just a (known)
> >matrix.
>
> Could you give an example? With the way you have stated your problem,
> Ian's response appears correct to me.
>
> Is the following code not an implementation of the definition
> of lambda (a scalar) times k (a matrix) ?
>
> k2 = zeros(size(k));
> for idx1 = 1:size(k,1)
> for idx2 = 1:size(k,2)
> k2(i,j) = lambda * k(idx1,idx2);
> end
> end
>
> If I haven't forgotten my linear algebra too badly, then that
> would mean that k1 would have to be the same size as k, and
> that L = k1 ./ k would have to be a matrix with all entries equal
> to lambda (except for those entries where k was 0.) So dividing
> any one k1 entry by its corresponding non-zero k entry would
> recover lambda.
> --
> "This quitting thing, it's a hard habit to break once you start."
> -- Walter Matthau

For example, I have the [a] matrix>
a =

     2 4 6 10
     4 20 50 80
     6 50 8 6
    10 80 6 30

I need to write now the [b] matrix>

b=

     8 50 6 10
     4 20 30 9
     7 50 8 6
    10 15 6 18

in such way that L*b=a were L is a unknown constant (scalar).

Along the same line, if I have the following matriceal equation>
( [k1] + [k2] ) * {u} = {f}
 [k1], [k2] - size n x n, {u} - size 1 x n and {f} - size 1 x n
I want to find L in such way that
( L*[k] ) * {u} = {f}
were only L is unknown and [k] = [k1] + [k2]

Thanks in advance !

Subject: Re: matrix problem

From: Roger Stafford

Date: 27 Jun, 2008 18:24:01

Message: 9 of 11

"John D'Errico" <woodchips@rochester.rr.com> wrote in message <g439hp$n2v
$1@fred.mathworks.com>...
> Why so much effort? The least squares solution
> is just this:
>
> lambda = k(:)\k1(:);
>
> John

  Yes, I stand corrected, John. That gives the same answer with much less effort.
I've been making more and more of such bloopers lately, I'm afraid.

Roger Stafford

Subject: Re: matrix problem

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 27 Jun, 2008 18:25:05

Message: 10 of 11

In article <c285fc5e-58ac-4693-8515-87464f84c507@r66g2000hsg.googlegroups.com>,
boguS <bteodoru@gmail.com> wrote:

>For example, I have the [a] matrix>
>a =
>
> 2 4 6 10
> 4 20 50 80
> 6 50 8 6
> 10 80 6 30
>
>I need to write now the [b] matrix>

>b=
>
> 8 50 6 10
> 4 20 30 9
> 7 50 8 6
> 10 15 6 18

>in such way that L*b=a were L is a unknown constant (scalar).

In that case, either '*' does not represent matrix-scalar
multiplication, or L is not a scalar.

What solution have you worked out "manually" for this example?


>Along the same line, if I have the following matriceal equation>
>( [k1] + [k2] ) * {u} = {f}
> [k1], [k2] - size n x n, {u} - size 1 x n and {f} - size 1 x n
>I want to find L in such way that
>( L*[k] ) * {u} = {f}
>were only L is unknown and [k] = [k1] + [k2]

If L is a scalar, then in that situation, L = 1.
If L is a matrix, then in that situation, L is the n x n identity
matrix.

--
  "We may gather out of history a policy, by the comparison and
  application of other men's forepassed miseries with our own like
  errors and ill deservings." -- Sir Walter Raleigh

Subject: Re: matrix problem

From: boguS

Date: 27 Jun, 2008 18:34:40

Message: 11 of 11

On 27 Iun, 21:25, rober...@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote:
> In article <c285fc5e-58ac-4693-8515-87464f84c...@r66g2000hsg.googlegroups.com>,
>
>
>
> boguS <bteod...@gmail.com> wrote:
> >For example, I have the [a] matrix>
> >a =
>
> > 2 4 6 10
> > 4 20 50 80
> > 6 50 8 6
> > 10 80 6 30
>
> >I need to write now the [b] matrix>
> >b=
>
> > 8 50 6 10
> > 4 20 30 9
> > 7 50 8 6
> > 10 15 6 18
> >in such way that L*b=a were L is a unknown constant (scalar).
>
> In that case, either '*' does not represent matrix-scalar
> multiplication, or L is not a scalar.
>
> What solution have you worked out "manually" for this example?
>
> >Along the same line, if I have the following matriceal equation>
> >( [k1] + [k2] ) * {u} = {f}
> > [k1], [k2] - size n x n, {u} - size 1 x n and {f} - size 1 x n
> >I want to find L in such way that
> >( L*[k] ) * {u} = {f}
> >were only L is unknown and [k] = [k1] + [k2]
>
> If L is a scalar, then in that situation, L = 1.
> If L is a matrix, then in that situation, L is the n x n identity
> matrix.
>
> --
> "We may gather out of history a policy, by the comparison and
> application of other men's forepassed miseries with our own like
> errors and ill deservings." -- Sir Walter Raleigh

Sorry, my mistake... [k] is not equal with ( [k1] + [k2] ), [k] is
just a known matrix.

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics