Symsum multidimensionalfunction error sym/colon

3 次查看(过去 30 天)
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
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 个评论
Walter Roberson
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
Michael S 2012-11-12
Ok, I made a while-loop and it seems to work out:
A00=zeros(4,4);
l=0;
while (norm(partko(l))~= 0)
A00 = A00+partko(l);
l=l+1;
end

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by