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:
how to creat matrix from loop result

Subject: how to creat matrix from loop result

From: jay

Date: 5 Apr, 2009 04:12:01

Message: 1 of 4

Hi,

I am trying to create a 1xn matrix from a loop

simply
for i=1:80;
A=[1 2 3 4];
B=[1 2 3 3;4 3 2 3;5 4 4 3; 9 8 9 0];
C=A*B^i
D=C(1)+C(2)*2+C(3)*3+C(4)*4
then we can get D values for different i, and Matrix E is what I need
E=[D(1), D(2) ....]

How to make this happen? thanks

Subject: how to creat matrix from loop result

From: Roger Stafford

Date: 5 Apr, 2009 08:02:01

Message: 2 of 4

"jay " <ssjzdl@gmail.com> wrote in message <gr9b2h$hcs$1@fred.mathworks.com>...
> Hi,
>
> I am trying to create a 1xn matrix from a loop
>
> simply
> for i=1:80;
> A=[1 2 3 4];
> B=[1 2 3 3;4 3 2 3;5 4 4 3; 9 8 9 0];
> C=A*B^i
> D=C(1)+C(2)*2+C(3)*3+C(4)*4
> then we can get D values for different i, and Matrix E is what I need
> E=[D(1), D(2) ....]
>
> How to make this happen? thanks

 E = zeros(1,n);
 T = eye(4);
 for k = 1:n
  T = T*B;
  E(k) = A*T*A.';
 end

  Warning: Around about n = 13, 14, or 15, matlab's 53 bits will be incapable of representing the integers in E exactly because of their excessive sizes.

Roger Stafford

Subject: how to creat matrix from loop result

From: Roger Stafford

Date: 5 Apr, 2009 10:01:01

Message: 3 of 4

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <gr9ohp$9s3$1@fred.mathworks.com>...
> E = zeros(1,n);
> T = eye(4);
> for k = 1:n
> T = T*B;
> E(k) = A*T*A.';
> end
> .......

  Or, requiring one less matrix multiplication per step:

 E = zeros(1,n);
 T = A.';
 for k = 1:n
  T = B*T;
  E(k) = A*T;
 end

Roger Stafford

Subject: how to creat matrix from loop result

From: jay

Date: 5 Apr, 2009 16:21:01

Message: 4 of 4

thanks so much. it is part of one optimization problem. I kinda got stuck even after this

basically, I have
for i=1:80
A=[1 0 0 0];
B=[1-x x 0 0; 0 1-y y 0; 0 0 1-z z; 0 0 0 1];
C=A*B^i'
D=C(1)+C(2)*2+C(3)*3+C(4)*4
for all i, we get D values for matrix E
E=[D(1) D(2)................D(80)]

at the same time,

for i=1:80;
F=exp(0.0173*i)
G=[F(1) F(2) ............F(80)]

then use optimization find x y z values
[x y z resnorm]= laqcurvefit( )

can I get more help. I would really appreciate this. thanks

Tags for 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