I created the m.file to plot alpha vs Vnorm but the vector is not the same length ,its request to hellp me at this stage
D=15;
tmpI=eye(D);
ket0=tmpI(:,1); %|0>
ket1=tmpI(:,2); %|1>
ket2=tmpI(:,3); %|2>
ket3=tmpI(:,4); %|3>
ket4=tmpI(:,5); %|4>
ket5=tmpI(:,6); %|5>
ket6=tmpI(:,7); %|6>
ket7=tmpI(:,8); %|7>
ket8=tmpI(:,9); %|8>
ket9=tmpI(:,10); %|9>
ket10=tmpI(:,11); %|10>
ket11=tmpI(:,12); %|11>
ket12=tmpI(:,13); %|12>
ket13=tmpI(:,14); %|13>
ket14=tmpI(:,15); %|14>
sym n
alpha1 =0.03;
ketalpha1 = symsum(exp(-abs(alpha)^2 * alpha^n / sqrt(factorial(n)) ), n, 0, 14)*(ket1+ket2+ket3+ket4+ket5+ket6+ket7+ket8+ket9+ket10+ket11+ket12+ket13+ket14);
sym n
alpha2 =0.06;
ketalpha2 = symsum(exp(-abs(alpha)^2 * alpha^n / sqrt(factorial(n)) ), n, 0, 14)*(ket1+ket2+ket3+ket4+ket5+ket6+ket7+ket8+ket9+ket10+ket11+ket12+ket13+ket14);
sym n
alpha3 =0.09;
ketalpha3 = symsum(exp(-abs(alpha)^2 * alpha^n / sqrt(factorial(n)) ), n, 0, 14)*(ket1+ket2+ket3+ket4+ket5+ket6+ket7+ket8+ket9+ket10+ket11+ket12+ket13+ket14);
sym n
alpha4 =0.12;
ketalpha4 = symsum(exp(-abs(alpha)^2 * alpha^n / sqrt(factorial(n)) ), n, 0, 14)*(ket1+ket2+ket3+ket4+ket5+ket6+ket7+ket8+ket9+ket10+ket11+ket12+ket13+ket14);
sym n
alpha5 =0.15;
ketalpha5 = symsum(exp(-abs(alpha)^2 * alpha^n / sqrt(factorial(n)) ), n, 0, 14)*(ket1+ket2+ket3+ket4+ket5+ket6+ket7+ket8+ket9+ket10+ket11+ket12+ket13+ket14);
sym n
alpha6 =0.18;
ketalpha6 = symsum(exp(-abs(alpha)^2 * alpha^n / sqrt(factorial(n)) ), n, 0, 14)*(ket1+ket2+ket3+ket4+ket5+ket6+ket7+ket8+ket9+ket10+ket11+ket12+ket13+ket14);
creation=circshift(diag(sqrt(0:1:14)),-1);
annihilation=creation';
V1=annihilation*ketalpha1-alpha1*ketalpha1;
V2=annihilation*ketalpha2-alpha2*ketalpha2;
V3=annihilation*ketalpha3-alpha3*ketalpha3;
V4=annihilation*ketalpha4-alpha4*ketalpha4;
V5=annihilation*ketalpha5-alpha5*ketalpha5;
V6=annihilation*ketalpha6-alpha6*ketalpha6;
Vnorm1=V1*V1';
Vnorm2=V2*V2';
Vnorm3=V3*V3';
Vnorm4=V4*V4';
Vnorm5=V5*V5';
Vnorm6=V6*V6';
plot(Vnorm1,alpha1,Vnorm2,alpha2,Vnorm3,alpha3,Vnorm4,alpha4,Vnorm5,alpha5,Vnorm6,alpha6);

 Akzeptierte Antwort

Dyuman Joshi
Dyuman Joshi am 11 Feb. 2023
Verschoben: Image Analyst am 11 Feb. 2023

1 Stimme

I have tidied up your code. Avoid using dynamically named variables as much as you can, it is not recommended, Indexing is much simpler and efficient.
Coming onto the issue, alpha1 is a scalar and Vnorm1 is a matrix. How exactly do you plan to plot a scalar against a matrix (or vice-versa) ?
D = 15;
tmpI = eye(D);
%sum of ket1 to ket14 is
ket = [0;ones(14,1)];
syms n
ct = 6;
creation = circshift(diag(sqrt(0:1:14)),-1);
annihilation = creation';
%pre-allocation
[ketalpha, V, Vnorm] = deal(cell(1,ct));
for k=1:ct
alpha = 0.03*k;
temp0 = symsum(exp(-abs(alpha)^2 * alpha^n / sqrt(factorial(n)) ), n, 0, 14)*ket;
ketalpha{k} = temp0;
temp1 = annihilation*temp0 - alpha*temp0;
V{k} = temp1;
Vnorm{k} = temp1*temp1';
end

19 Kommentare

Abu Zar
Abu Zar am 11 Feb. 2023
Bearbeitet: Image Analyst am 11 Feb. 2023
Hello sir,your code is very helpful. Please, how to put the another's values 0.06,0.09,0.12,0.15,0.18 for alpha? I want to find the plot of alpha, Vnorm.
I think the plot will if I find the numeric value. How I can find the numeric value of for plot? For example of the plot given below
xlist=1:1:10
xlist = 1×10
1 2 3 4 5 6 7 8 9 10
for id=1:10
ylist(id)=xlist(id)*2;
end
plot(xlist, ylist, 'b.-', 'MarkerSize', 20)
grid on
"Please, how to put the another's values 0.06,0.09,0.12,0.15,0.18 for alpha?"
I have already taken care of that in the code, as you can see below
ct=6;
for k=1:ct
alpha = 0.03*k
So, here
ketalpha{1} is ketalpha1, ketalpha{2} is ketalpha2 and so on,
Similarly, V{1} is V1, V{2} is V2, ... Vnorm{1} is Vnorm1, Vnorm{2} is Vnorm2 ...
"I want to find the plot of alpha, Vnorm."
As I mentioned earlier, alpha is a scalar and Vnorm is a matrix.
How exactly do you plan to plot a scalar against a matrix? The example you have shown is plotting vector vs vector.
What exactly are you trying to do?
Abu Zar
Abu Zar am 13 Feb. 2023
Bearbeitet: Abu Zar am 13 Feb. 2023
Thank you very much.
basically i want to do this two question
With the result you want to get, I think you have the multiplication order incorrect -
D = 15;
tmpI = eye(D);
%sum of ket1 to ket14 is
%generalised this line of code for any value of D
ket = sum(tmpI(:,2:D),2);
syms n
ct = 6;
creation = circshift(diag(sqrt(0:1:(D-1))),-1);
annihilation = creation';
%pre-allocation
%[ketalpha, V, Vnorm] = deal(cell(1,ct));
Vnorm = zeros(1,ct);
alpha = 0.03*(1:ct);
%loop for calculation
for k = 1:ct
temp0 = symsum(exp(-abs(alpha(k))^2 * alpha(k)^n / sqrt(factorial(n)) ), n, 0, 14)*ket;
%ketalpha{k} = temp0;
temp1 = annihilation*temp0 - alpha(k)*temp0;
%V{k} = temp1;
Vnorm(k) = temp1'*temp1;
end
plot(alpha,Vnorm, '-*k')
xlim([0 0.21])
xticks(0:0.03:0.21)
xlabel('alpha', 'Color', 'b', 'FontSize', 15)
ylabel('Vnorm', 'Color', 'b', 'FontSize', 15)
Abu Zar
Abu Zar am 13 Feb. 2023
it's outstanding.
thank you very much.
Dyuman Joshi
Dyuman Joshi am 13 Feb. 2023
You are welcome!
Abu Zar
Abu Zar am 14 Feb. 2023
Hi,
the temp1>>1,i want to evaulate the temp1<<1,
I try to use vpa(temp) then double(vpa(temp) but i did not get my result.
can i get my result if i use any other technique in this m.file.
thanks.
Dyuman Joshi
Dyuman Joshi am 14 Feb. 2023
I dont understand what you are trying to convey.
Abu Zar
Abu Zar am 14 Feb. 2023
let me explain little again
i want Temp1’*temp1 should be << 1 but my value Temp1’*temp1 >>1 ,also plot show this,
Can you check it?
somone recommend me to use a column vector to define temp0. For example.
temp0=zeros(D,1);
for id =0:D-1
Temp0(id)=...
end
Then, you can give a numeric result.
i try my self but not know how to do this above recommandtion.
Dyuman Joshi
Dyuman Joshi am 16 Feb. 2023
Bearbeitet: Dyuman Joshi am 16 Feb. 2023
"my value Temp1’*temp1 >>1"
Yes the values are big, in the order of 10^4, do you mean to say this?
"i want Temp1’*temp1 should be << 1"
For that you will have to change the data. For the given data, you can't modify the outcome.
"Then, you can give a numeric result."
Which result?
Abu Zar
Abu Zar am 21 Feb. 2023
Hello Sir,
please help me to put follow this message in these codes ;
---->Temp0 is a sum from n=0 to n=14. try the following and find the result, please.
for n=0:14
temp0 =temp0+ double(symsum(exp(-0.5*abs(alpha(k))^2)* alpha(k)^n / sqrt(factorial(n)), n, 0, 14)*ket);
end
Thank you
Dyuman Joshi
Dyuman Joshi am 21 Feb. 2023
Message? as in a comment?
Or do you want to include this in the code?
Abu Zar
Abu Zar am 21 Feb. 2023
Yes I want to include 🙏 Thank you
D = 15;
tmpI = eye(D);
%sum of ket1 to ket14 is
%generalised this line of code for any value of D
ket = sum(tmpI(:,2:D),2);
syms n
ct = 6;
creation = circshift(diag(sqrt(0:1:(D-1))),-1);
annihilation = creation';
%pre-allocation
Vnorm = zeros(1,ct);
alpha = 0.03*(1:ct);
temp0=0;
%loop for calculation
for k = 1:ct
temp0 = temp0 + symsum(exp(-abs(alpha(k))^2*alpha(k)^n/sqrt(factorial(n))), n, 0, 14)*ket;
temp1 = annihilation*temp0 - alpha(k)*temp0;
Vnorm(k) = temp1'*temp1;
end
plot(alpha,Vnorm, '-*k')
xlim([0 0.21])
xticks(0:0.03:0.21)
xlabel('alpha', 'Color', 'b', 'FontSize', 15)
ylabel('Vnorm', 'Color', 'b', 'FontSize', 15)
Abu Zar
Abu Zar am 21 Feb. 2023
Sir,in this way i improved my plot this becoming less then 1 but last value is very large ,please help me to solve this point,you can see my plot.
Abu Zar
Abu Zar am 21 Feb. 2023
Bearbeitet: Abu Zar am 21 Feb. 2023
D = 15;
tmpI = eye(D);
%sum of ket1 to ket14 is
%generalised this line of code for any value of D
ket = sum(tmpI(:,1:D),1)';
syms n
ct = 6;
creation = circshift(diag(sqrt(0:1:(D-1))),-1);
annihilation =creation';
%pre-allocation
%[ketalpha, V, Vnorm] = deal(cell(1,ct));
Vnorm = zeros(1,ct);
alpha = 0.03*(1:ct);
temp0=0;
%loop for calculation
for k = 1:ct
temp0 =14*temp0+double(symsum(exp(0.5*(-abs(alpha(k))^2))* alpha(k)^n / sqrt(factorial(n)), n, 0, 14)*ket);
%ketalpha{k} = temp0;
%temp2= annihilation*temp0;
temp1 = annihilation*temp0 - alpha(k)*temp0;
%V{k} = temp1;
Vnorm(k) = temp1'*temp1;
end
plot(alpha,Vnorm, '-*k')
xlim([0 0.21])
%xticks(0:0.03:0.21)
xlabel('alpha', 'Color', 'b', 'FontSize', 15)
ylabel('Vnorm', 'Color', 'b', 'FontSize', 15)
Dyuman Joshi
Dyuman Joshi am 21 Feb. 2023
You changed the definition of the variable 'ket', I don't know why.
At this point, I do not know what you are trying to achieve.
If you are doing a Homework question, copy and paste the original question. Otherwise, I don't understand what you are trying to convey.
Abu Zar
Abu Zar am 22 Feb. 2023
hello sir you know my codes ,i check values of every variables but i did not got the values of n, i put the values of n from 0 to 14.
Dyuman Joshi
Dyuman Joshi am 22 Feb. 2023
"but i did not got the values of n"
Because you have not assigned any value to n.
"i put the values of n from 0 to 14."
Yes, to find the value of a sum, with respect to a variable. But the value of n has not been explicitly defined.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Distribution Plots finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by