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:
beginner quest:cross product .... arrays

Subject: beginner quest:cross product .... arrays

From: ravi

Date: 20 Feb, 2010 02:46:03

Message: 1 of 7

I have 2 matrices.

A =

   658 96 1
   760 292 1
   777 353 1

B =

        1072 103 1
        1089 298 1
        1034 357 1

Using the cross function how can I cross multiple each row one at a time? I know I have to use a for loop. I've been trying but just dont know how.

Can anyone help.
Best
ravi

Subject: beginner quest:cross product .... arrays

From: Matthew

Date: 20 Feb, 2010 03:35:05

Message: 2 of 7

You don't need a loop. Just use the third argument in cross, i.e.

cross(A,B,1)

"ravi " <ravi_071@hotmail.com> wrote in message <hlnidb$9u1$1@fred.mathworks.com>...
> I have 2 matrices.
>
> A =
>
> 658 96 1
> 760 292 1
> 777 353 1
>
> B =
>
> 1072 103 1
> 1089 298 1
> 1034 357 1
>
> Using the cross function how can I cross multiple each row one at a time? I know I have to use a for loop. I've been trying but just dont know how.
>
> Can anyone help.
> Best
> ravi

Subject: beginner quest:cross product .... arrays

From: ravi

Date: 20 Feb, 2010 04:00:22

Message: 3 of 7

I don't think that will work matthew.

I tried it ,i.e. cross(A,B,1) and got the same result.

i am looking to cross multiply each row of A by each row of B.

So for example.

cross(A(1,:), B(1,:)) will give me :

>> cross(A(1,:), B(1,:))

ans =

          -7 414 -35138


I now want to do this for all the following rows of A and B. That's why I thought a for loop was needed.

Any other suggestion?

Thanks
ravi

Subject: beginner quest:cross product .... arrays

From: ravi

Date: 20 Feb, 2010 04:04:03

Message: 4 of 7

I don't think that will work matthew.

I tried it ,i.e. cross(A,B,1) and got the same result.

i am looking to cross multiply each row of A by each row of B.

So for example.

cross(A(1,:), B(1,:)) will give me :

>> cross(A(1,:), B(1,:))

ans =

          -7 414 -35138


I now want to do this for all the following rows of A and B. That's why I thought a for loop was needed.

Any other suggestion?

Thanks
ravi

Subject: beginner quest:cross product .... arrays

From: ravi

Date: 20 Feb, 2010 04:04:03

Message: 5 of 7

I don't think that will work matthew.

I tried it ,i.e. cross(A,B,1) and got the same result.

i am looking to cross multiply each row of A by each row of B.

So for example.

cross(A(1,:), B(1,:)) will give me :

>> cross(A(1,:), B(1,:))

ans =

          -7 414 -35138


I now want to do this for all the following rows of A and B. That's why I thought a for loop was needed.

Any other suggestion?

Thanks
ravi

Subject: beginner quest:cross product .... arrays

From: Wayne King

Date: 20 Feb, 2010 04:31:04

Message: 6 of 7

"ravi " <ravi_071@hotmail.com> wrote in message <hlnmvj$ghf$1@fred.mathworks.com>...
> I don't think that will work matthew.
>
> I tried it ,i.e. cross(A,B,1) and got the same result.
>
> i am looking to cross multiply each row of A by each row of B.
>
> So for example.
>
> cross(A(1,:), B(1,:)) will give me :
>
> >> cross(A(1,:), B(1,:))
>
> ans =
>
> -7 414 -35138
>
>
> I now want to do this for all the following rows of A and B. That's why I thought a for loop was needed.
>
> Any other suggestion?
>
> Thanks
> ravi

Hi Ravi,

For the way you have your matrices,
cross(A',B')

the columns of the answer are the cross products of the rows of A and B.

Hope that helps,
Wayne

Subject: beginner quest:cross product .... arrays

From: ravi

Date: 20 Feb, 2010 04:50:05

Message: 7 of 7

Hey Wayne,

Thanks man.

All the best
ravi

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