Codes for coherent state function?

 Respuesta aceptada

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

12 comentarios

Abu Zar
Abu Zar el 14 de En. de 2023
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)
Abu Zar
Abu Zar el 14 de En. de 2023
Thank you very much
Abu Zar
Abu Zar el 8 de Feb. de 2023
Hello sir,can i use alpha=0.5 instead of alpha=sym(0.5)?
Walter Roberson
Walter Roberson el 8 de Feb. de 2023
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.
Abu Zar
Abu Zar el 8 de Feb. de 2023
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)
Abu Zar
Abu Zar el 9 de Feb. de 2023
Hi , i see you create "25 X 1'',how we can create "25 X 25".
Zar
Zar el 9 de Feb. de 2023
v.nice
Walter Roberson
Walter Roberson el 9 de Feb. de 2023
remove the sum() from resultsym to get length(alpha) by length(0:11), which would be removing the summation from the formula
Abu Zar
Abu Zar el 11 de Feb. de 2023
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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Quantum Mechanics en Centro de ayuda y File Exchange.

Preguntada:

el 13 de En. de 2023

Comentada:

el 11 de Feb. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by