Vector must be the same length.
3 ビュー (過去 30 日間)
古いコメントを表示
I created the m.file to plot alpha vs Vnorm but the vector is not the same length ,its request to hellp me at this stage
D=15;
tmpI=eye(D);
ket0=tmpI(:,1); %|0>
ket1=tmpI(:,2); %|1>
ket2=tmpI(:,3); %|2>
ket3=tmpI(:,4); %|3>
ket4=tmpI(:,5); %|4>
ket5=tmpI(:,6); %|5>
ket6=tmpI(:,7); %|6>
ket7=tmpI(:,8); %|7>
ket8=tmpI(:,9); %|8>
ket9=tmpI(:,10); %|9>
ket10=tmpI(:,11); %|10>
ket11=tmpI(:,12); %|11>
ket12=tmpI(:,13); %|12>
ket13=tmpI(:,14); %|13>
ket14=tmpI(:,15); %|14>
sym n
alpha1 =0.03;
ketalpha1 = symsum(exp(-abs(alpha)^2 * alpha^n / sqrt(factorial(n)) ), n, 0, 14)*(ket1+ket2+ket3+ket4+ket5+ket6+ket7+ket8+ket9+ket10+ket11+ket12+ket13+ket14);
sym n
alpha2 =0.06;
ketalpha2 = symsum(exp(-abs(alpha)^2 * alpha^n / sqrt(factorial(n)) ), n, 0, 14)*(ket1+ket2+ket3+ket4+ket5+ket6+ket7+ket8+ket9+ket10+ket11+ket12+ket13+ket14);
sym n
alpha3 =0.09;
ketalpha3 = symsum(exp(-abs(alpha)^2 * alpha^n / sqrt(factorial(n)) ), n, 0, 14)*(ket1+ket2+ket3+ket4+ket5+ket6+ket7+ket8+ket9+ket10+ket11+ket12+ket13+ket14);
sym n
alpha4 =0.12;
ketalpha4 = symsum(exp(-abs(alpha)^2 * alpha^n / sqrt(factorial(n)) ), n, 0, 14)*(ket1+ket2+ket3+ket4+ket5+ket6+ket7+ket8+ket9+ket10+ket11+ket12+ket13+ket14);
sym n
alpha5 =0.15;
ketalpha5 = symsum(exp(-abs(alpha)^2 * alpha^n / sqrt(factorial(n)) ), n, 0, 14)*(ket1+ket2+ket3+ket4+ket5+ket6+ket7+ket8+ket9+ket10+ket11+ket12+ket13+ket14);
sym n
alpha6 =0.18;
ketalpha6 = symsum(exp(-abs(alpha)^2 * alpha^n / sqrt(factorial(n)) ), n, 0, 14)*(ket1+ket2+ket3+ket4+ket5+ket6+ket7+ket8+ket9+ket10+ket11+ket12+ket13+ket14);
creation=circshift(diag(sqrt(0:1:14)),-1);
annihilation=creation';
V1=annihilation*ketalpha1-alpha1*ketalpha1;
V2=annihilation*ketalpha2-alpha2*ketalpha2;
V3=annihilation*ketalpha3-alpha3*ketalpha3;
V4=annihilation*ketalpha4-alpha4*ketalpha4;
V5=annihilation*ketalpha5-alpha5*ketalpha5;
V6=annihilation*ketalpha6-alpha6*ketalpha6;
Vnorm1=V1*V1';
Vnorm2=V2*V2';
Vnorm3=V3*V3';
Vnorm4=V4*V4';
Vnorm5=V5*V5';
Vnorm6=V6*V6';
plot(Vnorm1,alpha1,Vnorm2,alpha2,Vnorm3,alpha3,Vnorm4,alpha4,Vnorm5,alpha5,Vnorm6,alpha6);
0 件のコメント
採用された回答
Dyuman Joshi
2023 年 2 月 11 日
移動済み: Image Analyst
2023 年 2 月 11 日
I have tidied up your code. Avoid using dynamically named variables as much as you can, it is not recommended, Indexing is much simpler and efficient.
Coming onto the issue, alpha1 is a scalar and Vnorm1 is a matrix. How exactly do you plan to plot a scalar against a matrix (or vice-versa) ?
D = 15;
tmpI = eye(D);
%sum of ket1 to ket14 is
ket = [0;ones(14,1)];
syms n
ct = 6;
creation = circshift(diag(sqrt(0:1:14)),-1);
annihilation = creation';
%pre-allocation
[ketalpha, V, Vnorm] = deal(cell(1,ct));
for k=1:ct
alpha = 0.03*k;
temp0 = symsum(exp(-abs(alpha)^2 * alpha^n / sqrt(factorial(n)) ), n, 0, 14)*ket;
ketalpha{k} = temp0;
temp1 = annihilation*temp0 - alpha*temp0;
V{k} = temp1;
Vnorm{k} = temp1*temp1';
end
19 件のコメント
Dyuman Joshi
2023 年 2 月 22 日
"but i did not got the values of n"
Because you have not assigned any value to n.
"i put the values of n from 0 to 14."
Yes, to find the value of a sum, with respect to a variable. But the value of n has not been explicitly defined.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!