# How introduce column vector in M-file?

1 Ansicht (letzte 30 Tage)
Abu Zar am 19 Feb. 2023
how I improved my file to get { temp1<<1}, I am stuck here.
i gto sugestion to introduce column vector for temp0 but i am fail in this stage
##### 7 Kommentare6 ältere Kommentare anzeigen6 ältere Kommentare ausblenden
Walter Roberson am 19 Feb. 2023
double() or vpa()
The exp() terms I tested were exp(-1e-9) to exp(-1e-15). Precision is low in that range but the values should be distinguishable from 1.

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Sulaymon Eshkabilov am 19 Feb. 2023
Here is the corrected code:
D = 15;
tmpI = eye(D);
ket = sum(tmpI(:,2:D),2);
syms n
ct = 6;
creation = circshift(diag(sqrt(0:1:(D-1))),-1);
annihilation = creation';
Vnorm = zeros(1,ct);
alpha = 0.03*(1:ct);
%loop for calculation
for k = 1:ct
temp0 = double(symsum(exp(-abs(alpha(k))^2 * alpha(k)^n / sqrt(factorial(n)) ), n, 0, 14)*ket);
ketalpha(k,:) = temp0; % Data from each iteration is stored
temp1 = annihilation*temp0 - alpha(k)*temp0;
V(k,:) = temp1; % Data from each iteration is stored
Vnorm(k) = temp1'*temp1;
end
plot(alpha,Vnorm, '-*k')
xlim([0 0.21])
xlabel('$\alpha$', 'Interpreter', 'latex', 'Color', 'b', 'FontSize', 15)
ylabel('Vnorm', 'Color', 'b', 'FontSize', 15)
whos temp0 ketalpha temp1 V Vnorm
Name Size Bytes Class Attributes V 6x15 720 double Vnorm 1x6 48 double ketalpha 6x15 720 double temp0 15x1 120 double temp1 15x1 120 double
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Find more on Quantum Mechanics in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by