Codes for coherent state function?
显示 更早的评论
Summation n=0 to10 exp-abs(alpha)^2*alpha^n/sqrtfactorial(n)
采纳的回答
syms alpha n
result = symsum(exp(-abs(alpha)^2 * alpha^n / sqrt(factorial(n)) ), n, 0, 10)
result =

12 个评论
if we put alpha=0.5 the code become?
syms alpha n
result = symsum(exp(-abs(alpha)^2 * alpha^n / sqrt(factorial(n)) ),aplha,0.5, n, 0, 10)
syms n
alpha = sym(0.5)
result = symsum(exp(-abs(alpha)^2 * alpha^n / sqrt(factorial(n)) ), n, 0, 10)
Thank you very much
Hello sir,can i use alpha=0.5 instead of alpha=sym(0.5)?
On the special case that alpha is a negative power of 2 (0.5, 0.25, 0.125 and so on) greater than 2^-512 you can use the exact decimal equivalent for alpha without using sym()
The same is true if alpha is an exact integer multiple of a negative power of 2 and the multiple does not exceed 2^53 and you specify alpha as a fraction, such as alpha = 83617/2^37. However the larger the denominator, the higher the risk that matlab might approximate as a different fraction.
I Just use alpha=0.05
And i want calculate different alpha using a list and “ for “ iteration to calculate the result , one by one.
help me with one example thank you very much.
format long g
syms n
alpha = sym(0.05)
alpha =
result1 = symsum(exp(-abs(alpha)^2 * alpha^n / sqrt(factorial(n)) ), n, 0, 10)
result1 =

syms n
alpha = 0.05
alpha =
0.05
result2 = symsum(exp(-abs(alpha)^2 * alpha^n / sqrt(factorial(n)) ), n, 0, 10)
result2 =

result1 - result2
ans =
0
Alpha = rand
Alpha =
0.691938609323685
alpha = sym(Alpha)
alpha =
result3 = symsum(exp(-abs(alpha)^2 * alpha^n / sqrt(factorial(n)) ), n, 0, 10)
result3 =

alpha = Alpha
alpha =
0.691938609323685
result4 = symsum(exp(-abs(alpha)^2 * alpha^n / sqrt(factorial(n)) ), n, 0, 10)
result4 =

result3 - result4
ans =

double(ans)
ans =
-9.46009976357279e-18
This shows that for some alpha values you can get away with using numeric alpha, but for other alpha values you need to use sym() to get an accurate answer.
In particular if your input alpha has more than 26 bits of precision, the automatic conversion of abs(alpha)^2 might not match abs(sym(alpha))^2
format long g
syms n
alpha = linspace(0.01, 0.99, 25);
inner = exp(-abs(sym(alpha)).^2 .* sym(alpha).^n ./ sqrt(factorial(n)) )
inner =

resultsym = sum(subs(inner, n, (0:10).'),1).';
result = double(resultsym)
result = 25×1
10.9998989978882
10.9972830981744
10.9908097750576
10.980037695147
10.9645002860003
10.9437012720096
10.9171106809702
10.8841614122063
10.8442464792823
10.7967170574898
plot(alpha, result)

Hi , i see you create "25 X 1'',how we can create "25 X 25".
remove the sum() from resultsym to get length(alpha) by length(0:11), which would be removing the summation from the formula
Hello sir,
I created this m.file to draw plot alpha vs Vnorm , but the vector is not the same length,I requetd you to look this file for my help to draw th plot.
Thank you
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Quantum Mechanics 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
