The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Matrix formed in for loop
Replies: 1   Last Post: Feb 27, 2013 11:50 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View  
Steven Lord

Posts: 18,038
Registered: 12/7/04
Re: Matrix formed in for loop
Posted: Feb 27, 2013 11:50 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Lakshmi " <> wrote in message
> Hi
> I am trying to generate a matrix in a for loop with it's elements as
> symbols rather than actual numbers. I want to later use this matrix in
> another loop where the symbols values are assigned but the values change
> with every loop.
> Initially I had tried putting the loop developing the matrix within the
> loop that gives the values, but it threw an error saying number of matrix
> elements should be definite.
> The problem I am having currently is when I execute this piece of code
> for cc1=1:4
> for cc2=1:4
> for cc3=1:4
> for cc4=1:4
> Tc(ac,1)=expand(T1(cc1))*(T2(cc2))*(T3(cc3))*(T4(cc4));
> ac=ac+1;
> end
> end
> end
> end
> where T1,2,3,4 are matrices with symbolic elements,
> I get this error
> ??? The following error occurred converting from sym to double:
> Error using ==> mupadmex
> Error in MuPAD command: DOUBLE cannot convert the input expression into a
> double array.
> If the input expression contains a symbolic variable, use the VPA function
> instead.

Preallocate Tc to be a _symbolic_ matrix not a numeric matrix.

Tc = sym(zeros(4^4, 1));

Steve Lord
To contact Technical Support use the Contact Us link on

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.