Error using symbolic toolbox

hi, i have a problem using the symbolic toolbox. after defining a symbol, i have to compute a simple calculation, in order to obtain the result in terms of the components of x (since x is a vector)
x=sym('x',[numel(L),1]);
k=zeros(4,4,numel(L));
for i=1:numel(L)
k(:,:,i)=E*x(i)/L(i)*[C(i)*C(i) C(i)*S(i) -C(i)*C(i) -C(i)*S(i) ;...
C(i)*S(i) S(i)*S(i) -C(i)*S(i) -S(i)*S(i) ;...
-C(i)*C(i) -C(i)*S(i) C(i)*C(i) C(i)*S(i) ;...
-C(i)*S(i) -S(i)*S(i) C(i)*S(i) S(i)*S(i)];
end
E is a number, defined before, L is a coloumn vector, C and S are coloumn vector, obviously with the same size of L, they are known vectors, defined in the first part of the script, NOT symbols. If i do the calculation element by element, that is writing
k(:,:,1)=E*x(1)/L(1)*[C(1)*C(1) C(1)*S(1) -C(1)*C(1) -C(1)*S(1) ;...
matlab gives me the result in terms of x1, without any problems. if i try to run the program using the for cycle the following error appears:
??? 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.
Error in ==> todo at 63
k(:,:,i)=E*x(i)/L(i)*[C(i)*C(i) C(i)*S(i) -C(i)*C(i) -C(i)*S(i) ;...
a solution? thanks in advance for the help

1 Comment

If you vpa() the k entry, it should show you which symbol still remains.

Sign in to comment.

Answers (3)

edit: matlab gives the result only if I type directly in the command window:
E*x(i)/L(i)*[C(i)*C(i) C(i)*S(i) -C(i)*C(i) -C(i)*S(i) ;...
in the other case, using the matrix k, it doesnt work
eg
C = randi(5,4,1)
S = randi([5 10],4,1)
L = randi(8,4,1)
E = 1;
%solution
CS = permute([C,S],[3 2 1]);
x = sym('x',[4,1]);
k = bsxfun(@times,permute(CS,[2 1 3]),CS)
outs = arrayfun(@(i1)E*x(i1)/L(i1)*kron([1 -1;-1 1],k(:,:,i1)),1:4,'un',0)
out = cat(3,outs{:})
Walter Roberson
Walter Roberson on 3 Feb 2012
Instead of assigning directly to k(:,:,i), assign to a temporary variable. Use vpa() on that variable and observe what symbolic variable names might be there. symvar() can also be useful for testing for such variables automatically. After analysis, assign the temporary variable to k(:,:,i)

Asked:

fa
on 3 Feb 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!