Why there is the error that the number of input parameters is insufficient?
2 views (last 30 days)
Show older comments
Henan Fang
on 18 Sep 2018
Commented: Henan Fang
on 19 Sep 2018
(x,y) is a function generated as the following codes. If I input,e.g., vpa(Tuu(0.2,0.3)), it will give a correct result. However, when I calculate the integration that "integral2(Tuu,0.01,pi/2,0,pi/4)", the error that the number of input parameters is insufficient appears, and the first error comes from "kuu =[-ku.*sin(x).*cos(y), -ku.*sin(x).*sin(y), kz]". Why there is the error, how to solve this problem? Many thanks!
function U=Tuu(x,y)
syms kz d
m = 2;
dd=2.106*(m+1);
vh = 4;
mu = 11;
delta = 8;
HBAR = 1.05457266e-34;
ME = 9.1093897e-31;
ELEC = 1.60217733e-19;
Kh = 2.106;
vKh = [0,0,0;Kh,0,0;-Kh,0,0;0,Kh,0;0,-Kh,0];
kc = sqrt(2.*ME.*ELEC/HBAR^2).*1e-10;
ku = kc.*sqrt(mu+delta);
kd = kc.*sqrt(mu-delta);
a3 = [pi/Kh,pi/Kh,sqrt(2).*pi/Kh];
kuu =[-ku.*sin(x).*cos(y), -ku.*sin(x).*sin(y), kz];
n=0:m;
for p=1:5;
for q=1:5;
tuu(p,q)= (sum((kuu + vKh(p,:)).^2)-ku^2).*(p==q)+ kc^2*vh*sum(exp(i.*n.*sum((vKh(q,:)-vKh(p,:)).*a3)))/(m+1).*(p~=q);
end
end
dtuu=det(tuu);
kz0=vpasolve(dtuu,kz);
kzz=kz0(real(vpa(kz0))>=0&imag(vpa(kz0))>=0);
tuu1=subs(tuu,kz,kzz(1));
tuu2=subs(tuu,kz,kzz(2));
tuu3=subs(tuu,kz,kzz(3));
tuu4=subs(tuu,kz,kzz(4));
tuu5=subs(tuu,kz,kzz(5));
tuu11=double(tuu1);
tuu22=double(tuu2);
tuu33=double(tuu3);
tuu44=double(tuu4);
tuu55=double(tuu5);
nuu1=null(tuu11);
nuu2=null(tuu22);
nuu3=null(tuu33);
nuu4=null(tuu44);
nuu5=null(tuu55);
piuu=[nuu1,nuu2,nuu3,nuu4,nuu5];
pei=[1;0;0;0;0];
A=piuu\pei;
psiuu1=A(1).*nuu1(1)*exp(i*kzz(1)*d)+A(2)*nuu2(1)*exp(i*kzz(2)*d)+A(3)*nuu3(1)*exp(i*kzz(3)*d)+A(4)*nuu4(1)*exp(i*kzz(4)*d)+A(5)*nuu5(1)*exp(i*kzz(5)*d);
psiuu2=A(1).*nuu1(2)*exp(i*kzz(1)*d)+A(2)*nuu2(2)*exp(i*kzz(2)*d)+A(3)*nuu3(2)*exp(i*kzz(3)*d)+A(4)*nuu4(2)*exp(i*kzz(4)*d)+A(5)*nuu5(2)*exp(i*kzz(5)*d);
psiuu3=A(1).*nuu1(3)*exp(i*kzz(1)*d)+A(2)*nuu2(3)*exp(i*kzz(2)*d)+A(3)*nuu3(3)*exp(i*kzz(3)*d)+A(4)*nuu4(3)*exp(i*kzz(4)*d)+A(5)*nuu5(3)*exp(i*kzz(5)*d);
psiuu4=A(1).*nuu1(4)*exp(i*kzz(1)*d)+A(2)*nuu2(4)*exp(i*kzz(2)*d)+A(3)*nuu3(4)*exp(i*kzz(3)*d)+A(4)*nuu4(4)*exp(i*kzz(4)*d)+A(5)*nuu5(4)*exp(i*kzz(5)*d);
psiuu5=A(1).*nuu1(5)*exp(i*kzz(1)*d)+A(2)*nuu2(5)*exp(i*kzz(2)*d)+A(3)*nuu3(5)*exp(i*kzz(3)*d)+A(4)*nuu4(5)*exp(i*kzz(4)*d)+A(5)*nuu5(5)*exp(i*kzz(5)*d);
Tuux=ku.*sin(x).*(imag(conj(psiuu1)*diff(psiuu1,d)+conj(psiuu2)*diff(psiuu2,d)+conj(psiuu3)*diff(psiuu3,d)+conj(psiuu4)*diff(psiuu4,d)+conj(psiuu5)*diff(psiuu5,d)));
U=@(x,y) subs(Tuux,d,dd);
end
0 Comments
Accepted Answer
Walter Roberson
on 18 Sep 2018
integral2(Tuu,0.01,pi/2,0,pi/4)
is equivalent for this purpose to
integral2(Tuu(),0.01,pi/2,0,pi/4)
which is to say that Tuu is called with no parameters, and is expected to output a function handle that will then be integrated with integral2.
You need
integral2(@Tuu,0.01,pi/2,0,pi/4)
9 Comments
Walter Roberson
on 19 Sep 2018
Note what I said about the code being too slow to be usable. I ran the integral2 for hours without producing a result.
At the very least you need to take out of the routine everything that can be pre-calculated, right down to the formula that you vpasolve on: solve() of that formula gives a symbolic form that you can pre-calculate. Then you would substitute the actual x and y values into that symbolic form.
More Answers (0)
See Also
Categories
Find more on Multirate Signal Processing 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!