필터 지우기
필터 지우기

Data show one value why all values not displying?

조회 수: 1 (최근 30일)
Abu Zar
Abu Zar 2023년 3월 20일
댓글: Abu Zar 2023년 3월 20일
i got the different values of fid but display only show only one value of fid
  댓글 수: 4
Matt J
Matt J 2023년 3월 20일
See my answer. You've done nothing to retain early fid values in the loop.
Abu Zar
Abu Zar 2023년 3월 20일
ok,can you help me in this point?

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

채택된 답변

Sachin
Sachin 2023년 3월 20일
편집: Sachin 2023년 3월 20일
I understand that you are not receiving the full output of fid. since you are not storing the output of fid in an array or vector. In each iteration fid will store a new calculated value. To store the value you have to use you can use indexing to save those values. Refer the following code :
% Define the number of states
D = 15;
% Initialize the annihilation and creation matrices
aannihilation_a = zeros(D);
creation_a = zeros(D);
aannihilation_b = zeros(D);
creation_b = zeros(D);
% Fill the off-diagonal elements of the annihilation and creation matrices
for k = 1:D-1
aannihilation_a(k,k+1) = sqrt(k);
creation_a(k+1,k) = sqrt(k);
aannihilation_b(k,k+1) = sqrt(k);
creation_b(k+1,k) = sqrt(k);
end
% Create the composite annihilation and creation operators
a1 = kron(aannihilation_a,aannihilation_b);
a2 = kron(creation_a,creation_b);
a3 = a1 - a2;
% Define the range of values for the parameter r
r_range = [0.01:0.01:0.10];
% Loop over each value of r in the range
i = 1; % to save from 1st index
for r = r_range
% Define the time evolution operator
u = exp(r*a3);
% Define the identity operator and the initial and final states
I = eye(D);
n = 10;
ket_0 = zeros(D, 1);
ket_0(1) = 1;
ket_1 = zeros(D, 1);
ket_1(2) = 1;
ket_n = zeros(D, 1);
ket_n(n+1) = 1;
bra_0 = ones(1, D);
bra_0(2:end) = 0;
bra_n_minus_1 = zeros(1, D);
bra_n_minus_1(n) = 1;
% Calculate the final state after time evolution
psi_ket = kron(I,bra_0)*u*kron(ket_n,ket_1);
psi_bra = psi_ket';
p = psi_bra*psi_ket;
psi_prime = psi_ket/sqrt(p);
% Calculate the fidelity between the final state and the target state
fid(i) = abs(bra_n_minus_1*psi_prime).^2; % store values
% Plot the fidelity as a function of r
plot(fid(i),r,'r*');
i = i+1;
hold on
end
% Set axis labels and legend
title('Fidelity vs r','fontsize',14);
xlabel('Fidelity','fontsize',14);
ylabel('r','fontsize',14);
grid on;
fid =
0.0707 0.0750 0.0795 0.0842 0.0892 0.0945 0.1001 0.1059 0.1121 0.1185
  댓글 수: 2
Abu Zar
Abu Zar 2023년 3월 20일
thank you very much.
Abu Zar
Abu Zar 2023년 3월 20일
Hello sir, can we change the plot line style ,in the MATLAB above codes, because when i write 'r--*' then i only gots *

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

추가 답변 (1개)

Matt J
Matt J 2023년 3월 20일
편집: Matt J 2023년 3월 20일
That's not unthinkable, if the points in the plot were generated one at a time and discarded:
for fid=linspace(0.01,0.1185,10)
plot(fid,fid,'xr'); hold on
end; hold off; axis padded
fid
fid = 0.1185

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by