Symsum multidimensionalfunction error sym/colon
이전 댓글 표시
A = [0 1 2 3; -1 0 -2 -3; 4 0 8 9; -6 -7 8 0]; t= 2; E = [0 0 0 0; 0 0 0 0; 0 1 0 0; -0 0 0 0];
function f = partko(k)
t=evalin('base','t'); % t is number in {1,2,...k,}
A=evalin('base','A'); % A is real 4x4-Matrix
E=evalin('base','E'); % E is real 4x4-Matrix, where all entries are 0, entry (i,j) is 1
f=((t^(k+1))/factorial(k+1))*kommpo2(E,A,k);
________
innerfuntkion %% commutator potential
function f = kommpo2(E,A,k)
a=E;
for i=1:1:k
a=komm(a,A);
end
f=a;
__
%% innerfunciton matrix commutator regular
function f = komm(E,A)
f=E*A-A*E;
__
I am running the symsum function in order to receive a sum > syms k; symsum(partko(k),0,Inf)
I seems, the inner function is to complicated for matlab to evaluate with symsum, since the following erroer message appears, even if sum is finite!:
EDU>> symsum(partko(k),0,10) Error using sym/colon (line 27) Cannot compute the number of steps from 1 to k by 1.
Error in kommpo2 (line 4) for i=1:1:k
Error in partko (line 6) f=((t^(k+1))/factorial(k+1))*kommpo2(E,A,k);
How can I modify my application? Anny ideas? Thank you very much.
답변 (1개)
Walter Roberson
2012년 11월 11일
You have the line
for i=1:1:k
In order for that to be calculated, k has to have a definite value. But it doesn't: it is the "syms k".
Please remember that when you have the line
symsum(partko(k),0,10)
that that means that the expression partko(k) should be evaluated, and that the result should be passed to symsum().
댓글 수: 5
Michael S
2012년 11월 11일
Walter Roberson
2012년 11월 11일
?? Commutating an infinite number of times is going to require an infinite time to process ?? Did you mean from (0:10) ?
It appears to me that what you want is probably to add those terms rather than use symsum(). symsum() does not add the terms: instead it finds the generalized summation expression for an indefinite variable value followed by substituting in the given limits -- similar in spirit to how one forms a definite integral. And just like how an indefinite integral has a "+ C" term that is expected to cancel out when subtracting the values at the two limits, so it is with symsum() -- that there might be an error in the lower terms (compared to just adding up the terms) that cancels out when one goes high enough. So if you have a particular number of terms (e.g., 0 to 10) then evaluate them individually and sum the result, rather than using the asymptotic symsum()
Michael S
2012년 11월 11일
Walter Roberson
2012년 11월 12일
It sounds as if you do not need to work symbolically at all, and instead just need a "while" loop.
Michael S
2012년 11월 12일
카테고리
도움말 센터 및 File Exchange에서 Calculus에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!