我想使用fortran:

其中ψ( psi
)是一个复杂的fortran变量。
现在,我通过定义两个新的复杂变量来解决此问题:
ir =(1.0,0.0)
和 ii =(0.0,1.0)
。
我使用这些仅选择方程的真实或虚构部分。通过这种方式,我将方程式分别求解为真实和虚构的部分。代码在这里:
do i = 1,nn
mod2 = (abs(psi(i)))**2
psi(i) = ir*(-beta*imag(der2(i)) + alpha*mod2*imag(psi(i))) + ii*(beta*real(der2(i)) - alpha*mod2*real(psi(i)))
end do
其中 psi
和 der2
是复杂的数组, nn
elements。
我想以更好的方式求解此方程,而不会将其分为两个方程式。我试图以这种方式解决它:
mod2 = abs(psi)**2
psi = -ii*(-beta*der2+alpha*mod2*psi)
但是它不起作用,因为相对于我使用的第一种方法,我获得了完全不同的值。对我来说,这是不起作用的,因为在第二种方法中,我没有评估实际部分。这是对的吗?
例如,我的PSI阵列的10°元素变为:\
- (-6.39094355774850412E-003,-6.04041029332164168E-003)(使用1°方法) 003
- )(2 °方法)\
有什么建议?
谢谢你!
I want to solve this equation by using Fortran:
)
Where ψ (psi
) is a complex Fortran variable.
Now, I am solving this by defining two new complex variables:
ir=(1.0,0.0)
and ii=(0.0,1.0)
.
I use these to select only the real or imaginary part of the equation. In this way I solve my equation separately for the real and imaginary part. The code is here:
do i = 1,nn
mod2 = (abs(psi(i)))**2
psi(i) = ir*(-beta*imag(der2(i)) + alpha*mod2*imag(psi(i))) + ii*(beta*real(der2(i)) - alpha*mod2*real(psi(i)))
end do
Where psi
and der2
are complex arrays with nn
elements.
I want to solve this equation in a better way without splitting it in two equations. I tried to solve it in this way:
mod2 = abs(psi)**2
psi = -ii*(-beta*der2+alpha*mod2*psi)
but it doesn't work because I obtain completely different values with respect to the first method I used. For me it makes sense that it doesn't work because in the second method I am not evaluating the real part. Is this right?
As an example, the 10° element of my psi array becomes:\
- (-6.39094355774850412E-003,-6.04041029332164168E-003) (with 1° method)\
- (-1.75266632213431602E-004,-6.21567692553507290E-003) (2° method)\
Any suggestion?
Thank you!
发布评论
评论(1)
问题是
mod2 = abs(psi)** 2
应该是mod2 = abs(dat)** 2
,但我认为
mod2的正确计算
是 sum(real(dat*conjg(dat)))我通过两种方法获得了相同的结果,并带有一些任意数据:
。
还带有您的定义
|ψ|的定义
我们也有一致的结果。随着代码
返回原始问题,我可以将问题复制
到
mod2 = abs(psi)** 2
而不是mod2 = abs(dat)** 2
The problem is
mod2 = abs(psi)**2
should have beenmod2 = abs(dat)**2
But I think that the correct calculation for
mod2
issum( real( dat*conjg(dat) ) )
I get the same result with both methods with some arbitrary data:
Test code
Also with your definition of
|ψ|
we have also consistent results.with code
Going back to the original problem, I can replicate the issue
with
mod2 = abs(psi)**2
instead ofmod2 = abs(dat)**2