# How do I use parameters in the upper and lower limits of an intergral?

4 次查看（过去 30 天）
Hi, I have the following code
if true
% code
end
syms h g x C n L p e E C m
h = 1.0545718E-34
g = 5.344285879E-28
m = 9.10938356E-31
E = h^2/8*m*L^2
y = - (exp(-(x*(g*1i + (- 2*g^2 + E)^(1/2)))/h)*(g*1i - (- 2*g^2 + E)^(1/2)))/(2*(E - 2*g^2)^(1/2)) + (exp(-(x*(g*1i - (- 2*g^2 + E)^(1/2)))/h)*(g*1i + (- 2*g^2 + E)^(1/2)))/(2*(E - 2*g^2)^(1/2))
z = - (exp(-(x*(g*(-i) + (- 2*g^2 + E)^(1/2)))/h)*(g*(-i) - (- 2*g^2 + E)^(1/2)))/(2*(E - 2*g^2)^(1/2)) + (exp(-(x*(g*(-i) - (- 2*g^2 + E)^(1/2)))/h)*(g*(-i) + (- 2*g^2 + E)^(1/2)))/(2*(E - 2*g^2)^(1/2))
v = i*h*diff(z, x)
S = y*z
W = [int(S, 0, L)] % Operator check hermiticity
vpa(W) % vpa= Variable precision arithmetic, simplifies the large fractions to nunmbers
however the upper limit set to L is not accepted by MATLAB. Is there any chance of telling MATLAB to treat this as a constant?
Thanks
##### 2 个评论显示 1更早的评论隐藏 1更早的评论
Sergio Manzetti 2018-1-4
Sorry. There was an error, but related to vpa(W). Removing this makes it work, although it looks horribly long.

### 采纳的回答

Birdman 2018-1-4
The same code works me without any error, including vpa(W). To decide number of digits, use the following:
vpa(W,3)
##### 1 个评论显示 无隐藏 无
Sergio Manzetti 2018-1-4
Thanks Birdman!

### 类别

Help CenterFile Exchange 中查找有关 Common Operations 的更多信息

### Community Treasure Hunt

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

Start Hunting!

Translated by