2017-09-03 65 views
0

我寫了下面的代碼在Fortran和具有功能definintion錯誤在FORTRAN

program bisection_method 
implicit none 
real:: a=2.5,b=4.5,c,f 

if (f(a)*f(b).gt.0) then 
    write(*,*) "error" 
else 
    do while ((b-a)/2.0>0.0001) 
    c = (a+b)/2.0 
    if (f(a)*f(c).lt.0) then 
     c = a 
    else 
     c = b 
    endif 
    enddo 
endif 

write(*,*)"the root is ",c 
end program 

function f(x) 
implicit none 
real::f,x 
f=(16*(x^3)-385*(x^2)+6000*(x)-3125) 
end function f 

錯誤並具有下列錯誤

fbisection.f90:24:9: 

    f=(16*(x^3)-385*(x^2)+6000*(x)-3125) 
     1 
Error: Expected a right parenthesis in expression at (1) 

任何想法,爲什麼發生這種情況函數定義? 感謝

回答

1

您與**,這是乘方運算符混淆^(該^字符不是在FORTRAN運營商)。

只需更換說符合:

f=(16*(x**3)-385*(x**2)+6000*(x)-3125) 
+0

不知道,謝謝! –