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 件のコメント
Walter Roberson
2012 年 2 月 3 日
If you vpa() the k entry, it should show you which symbol still remains.
回答 (3 件)
Andrei Bobrov
2012 年 2 月 3 日
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
2012 年 2 月 3 日
0 投票
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)
カテゴリ
ヘルプ センター および File Exchange で Functional Programming についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!