简体   繁体   English

Matlab-1D数值积分,函数存储在多个变量中

[英]Matlab- 1D Numerical integration with function stored in multiple variables

as you can see in the last few lines below, I'm trying to store my function on multiple variables because it gets rather ugly. 如您在下面的最后几行中所看到的,我正在尝试将我的函数存储在多个变量中,因为它变得很难看。 However, doing this yields the error shown below. 但是,这样做会产生如下所示的错误。

A fix for this would be to manually substitute k and kp , but this is precisely what I'm trying to avoid. 解决此问题的方法是手动替换kkp ,但这正是我要避免的方法。 Any help would be appreciated. 任何帮助,将不胜感激。 thanks! 谢谢!

clc
clear

hbar = 1.055e-34;
mo = 9.1095e-31;
q = 1.602e-19;
kb=1.38065e-23;
T=298;
Ef = -0.1*q; % -100meV in units Joules
V0 = 1*q;
L = 1e-9;



k = @(E) (2*mo*E/hbar.^2)^.5;
kp = @(E) (2*mo*(V0-E)/hbar.^2)^.5;
fun = @(E) (exp(-2*kp*L) .* ((16*k.^2 .* kp.^2) ./ ((k.^2 + kp.^2).^2))) .* exp(-E./(kb*T));

Q = integral(fun,0,inf);

Error below 错误如下

Undefined operator '*' for input arguments of type 'function_handle'.

Error in @(E)(exp(-2*kp*L).*((16*k.^2.*kp.^2)./((k.^2+kp.^2).^2))).*exp(-E./(kb*T))


Error in integralCalc/iterateScalarValued (line 314)
                fx = FUN(t);

Error in integralCalc/vadapt (line 132)
            [q,errbnd] = iterateScalarValued(u,tinterval,pathlen);

Error in integralCalc (line 83)
        [q,errbnd] = vadapt(@AToInfInvTransform,interval);

Error in integral (line 88)
Q = integralCalc(fun,a,b,opstruct);

Error in PS3_2 (line 17)
Q = integral(fun,0,inf);

Use this here 在这里使用

k = @(E) (2.*mo.*E./hbar.^2).^.5;
kp = @(E) (2.*mo.*(V0-E)./hbar.^2).^.5;
fun = @(E) (exp(-2*kp(E)*L).*((16*k(E).^2.*kp(E).^2)./((k(E).^2+kp(E).^2).^2))).*exp(-E./(kb*T));
Q = integral(fun,0,inf);

I think you need to pass the argument E , then are you sure kb*T is correct? 我认为您需要传递参数E ,那么您确定kb*T是正确的吗? Maybe kp(E)*T ? 也许kp(E)*T Then, you forgot the . 然后,您忘记了. is the sqrt for k and kp , or if it isn't a sqrt then the dot is on the wrong side of the power symbol. kkp的sqrt,或者如果不是sqrt,则点在幂符号的错误一侧。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM