From: Stephanie on
I would like to perform a loop in which symbols are involved while changing the symbol name. For example, having created the symbols:

syms a0 a1 a2 a3 a4

I want to have a for loop which will change the index 0,1,2,3...etc. on the 'a_' symbol using the current for loop index number. ie.
(this is just an example)
for i=0:4
funct=x+ai
end
where ai is the current symbol.

Is it possible to do this?
From: someone on
"Stephanie " <stu_ert(a)hotmail.com> wrote in message <hsf3so$s03$1(a)fred.mathworks.com>...
> I would like to perform a loop in which symbols are involved while changing the symbol name. For example, having created the symbols:
>
> syms a0 a1 a2 a3 a4
>
> I want to have a for loop which will change the index 0,1,2,3...etc. on the 'a_' symbol using the current for loop index number. ie.
> (this is just an example)
> for i=0:4
> funct=x+ai
> end
> where ai is the current symbol.
>
> Is it possible to do this?

If you really must, take a look at the answer to Q4.6 of the MATLAB FAQ at:

http://matlabwiki.mathworks.com/MATLAB_FAQ
From: Steven Lord on

"Stephanie " <stu_ert(a)hotmail.com> wrote in message
news:hsf3so$s03$1(a)fred.mathworks.com...
>I would like to perform a loop in which symbols are involved while changing
>the symbol name. For example, having created the symbols:
>
> syms a0 a1 a2 a3 a4
>
> I want to have a for loop which will change the index 0,1,2,3...etc. on
> the 'a_' symbol using the current for loop index number. ie. (this is
> just an example) for i=0:4
> funct=x+ai
> end
> where ai is the current symbol.
> Is it possible to do this?

In theory, yes. In practice, that's a Bad Idea. Store all your symbolic
variables in a vector and either index into the vector or SUM them all up.

a = sym(zeros(1, 5));
for k = 1:5
a(k) = sym(sprintf('a%d', k-1));
end

>> S = sum(a)

S =

a0 + a1 + a2 + a3 + a4

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ