# Error in the for loop of my function

4 views (last 30 days)
Athira T Das on 23 Jun 2022
Answered: Sai Charan Sampara on 23 Jun 2022
I am trying to plot the given function :
clear all
clc
syms z
syms s1 s2 m1 m2 j1 j2
w = 0.02;
M=1;
b=0.1;
z=linspace(-0.1,0.1);
for m1=0:M
for m2=0:M
for s1=0:m1/2
for j1=0:m1-2*s1
for s2=0:(M-m1)/2
for j2=0:M-m1-2*s2
A1=symsum(factorial(M)/(factorial(m1)*factorial(M-m1))*(1i)^(M-m1),m1,0,M);
A2=symsum(factorial(M)/(factorial(m2)*factorial(M-m2))*(-1i)^(M-m2),m2,0,M);
A3=symsum(((-1)^(s1)*factorial(m1))/(factorial(s1)*factorial(m1-2*s1))*(2*1i)^(m1-2*s1),s1,0,m1/2);
A4=symsum((1/(2*1i))^(m2+j1),j1,0,m1-2*s1)*(exp(2*b*z))*hermiteH(m2+j2,(1+(1i*b/2*w)));
A5=symsum(((-1)^(s2)*factorial(M-m1))/(factorial(s2)*factorial(M-m1-2*s2)*(2*1i)^(M-m1-2*s2)),s2,0,(M-m1)/2);
A6=symsum((1/(2*1i))^(M-m2+j2),j2,0,M-m1-2*s2)*(exp(2*b*z))*hermiteH(M-m2+j2,(1-(1i*b/2*w)));
W=A1*A2*A3*A4*A5*A6
end
end
end
end
end
end

Walter Roberson on 23 Jun 2022
The second parameter to symsum must be a scalar symbolic variable that will be summed over. However in your code, the second parameter is a numeric variable (assigned by your for loops)
It looks to me as if none of those for loops should be present.

Sai Charan Sampara on 23 Jun 2022
You seem to have used both a for loop and symsum function. The symsum function already runs a loop based on the index and range given as inputs.The first input of symsum must be a function of a variable(syms data type). Refer to the following link for more details on the symsum function: