(1)
% ket Transforms a vector into normalized column vector.
function w=ket(;5)
[y,x]=size(v);
if x>1,
w=v.';
else
w=v;
end % if
% normalisation
w=w/sqrt(w'*w);
(2)
function Q = bra_ket(Psi,Phi,f_op)
Q = integral3(@(r1,r2,r3) Psi(r1,r2,r3).*f_op(Phi(r1,r2,r3)),r1min,r1max,r2min,r2max,r3min,r3max)
end
(3)
function Q = bra_ket_traps(Psi,Phi,f_op,r1,r2,r3)
opPhi = f_op(Phi,r1,r2,r3); % Here you might need additional argument
Q = trapz(r3(1,1,:),trapz(r2(1,:,1),trapz(r1(:,:,1),conj(Psi).*(opPhi)),2),3);
end
(4)
% cohstate cohstate(alpha,M) gives the state vector of M elements for
% a coherent state with given alpha
function v=cohstate(alpha,M)
v=zeros(M,1);
v((0)+1)=1;
for n=0:M-2
v((n+1)+1)=alpha/sqrt(n+1)*v((n)+1);
end % for
v=v/sqrt(v'*v);

답변 (2개)

Luca Ferro
Luca Ferro 2023년 2월 9일

0 개 추천

there is a ';' in the function call on line 1: function w=ket(;5)
Voss
Voss 2023년 2월 9일

0 개 추천

Invalid syntax:
function w=ket(;5)
Inside the parentheses in a function definition should be a list of variable names. ";5" is not a list of variable names.
Maybe you meant:
function w=ket(v)

댓글 수: 11

Idrees Muhammad
Idrees Muhammad 2023년 2월 10일
Hi , whenever i put v codes also not working ,give the messssage( require more arguments for input)
Voss
Voss 2023년 2월 10일
I see you added more functions to the question. What's the complete error message you get now?
Idrees Muhammad
Idrees Muhammad 2023년 2월 10일
Idrees Muhammad
Idrees Muhammad 2023년 2월 10일
You need to either call ket from other code or else you need to go down to the command line and invoke it passing in values. For example
V = [2, 3-2i, -4]
ket(V)
Idrees Muhammad
Idrees Muhammad 2023년 2월 10일
Idrees Muhammad
Idrees Muhammad 2023년 2월 10일
Idrees Muhammad
Idrees Muhammad 2023년 2월 10일
Walter Roberson
Walter Roberson 2023년 2월 10일
Question: when you go to run cohstate by pressing the green Run button, where are you expecting matlab to look to find values for alpha and M?
Idrees Muhammad
Idrees Muhammad 2023년 2월 10일
i mean that how i put the numeric values for "alpha" and "m" to get the results of thie cohstate
Walter Roberson
Walter Roberson 2023년 2월 10일
If you are using the option on the green Run button to have it prompt you for the parameter values then OK, go ahead and do that. Personally I find doing that to be slow and not to offer me fine enough control for my purposes, but if that is what you want to do, go ahead and get back to us if you encounter further errors in your code.
Personally I use the techniques I described earlier https://www.mathworks.com/matlabcentral/answers/1909685-what-is-the-error-example#comment_2608885

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2023년 2월 9일

댓글:

2023년 2월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by