基本上,分配“说找到解决方案f(x)= 0 ....”。其中从x = 0到x-0.45,f(x)=积分(1/sqrt(2 * pi))exp(-t^2/2)dt。对不起,我无法找到如何把积分放在这里。积分计算使用梯形或辛普森规则
我的教授。给了我们一些提示如何开始。
start x
do i = 1,2,3...
fp = 1/sqrt(2*pi)exp(-x^2/2)
f = use trap,or simpson's rule to find the integration than subtract 0.45
x = x - (f/fp)
end do
这里是我做过什么
program main
implicit none
integer :: n, k, i
double precision :: h, a, fp, f, x1, x2, pi, blub, integ, e, dx, j, m
a = 0
n = 25
x1 = 0.5
pi = 4.0d0 * atan(1.0d0)
do i = 1, n
e = exp((-x1)**2.0d0/2.0d0)
print*, e
fp = (1.0d0/sqrt(2.0d0 * pi))* e
!start of the trapezoid
dx = (x1-a)/n !find dx by subtracting starting point from endpoint and divide by number of steps taken
m = (blub(a) + blub(x1))/2 !find the mean value of the integral
j = 0
do k=1, n-1
h = i
j = j + blub(h) !calculate the each step of the integral from one to n and add all together.
end do
integ = dx*(m+j) !result of the trapezoid method
print*, "integ: ", integ
f = integ - 0.45
a = x1
x1 = a - (f/fp)
print*, "x1: ",x1
print*, "a: ",a
print*, "f: ",f
print*, "fp: ", fp
print*, (x1-a)/n
end do
stop
end
double precision function blub (x)
double precision :: x
blub(x) = (1.0d0/sqrt(2.0d0 * (4.0d0 * atan(1.0d0))))*exp((-x)**2.0d0/2.0d0)
return
end
我做了所有的印刷找出我的错误可能。我意识到我的DX正在变得小,基于x1小于n。因为我的整合变成e^-310的数字,对0.45几乎没有影响,因此我的f保持不变,并且x1向上混乱...
如果有人可以向我解释我如何解决这个错误。
编辑:我确定我对梯形部分犯了一个错误,我只是不知道在哪里。 f应该随着每个循环而改变,但dx太小会阻止这种情况发生。
你会得到哪些错误? – 2014-12-01 17:43:13
他们都是语法错误。像无效字符一样,将一个变量从int变为real。我一直工作到凌晨5点,并开始失去焦点 – 2014-12-01 17:47:15
因此,您只是在这里发布它,以便某人完成您的硬件,甚至在您发现问题时甚至不给他提示? – 2014-12-01 18:18:59