Introduction:
Program:
! Iterative method for a nonlinear equation
real::x1,x2,check
x1=-1.5
check=x1
20 check=check+1.0
x1=check
19 x2=f(x1)
x1=x2
!write(*,*)check
if(abs(f(x2)-x2)<=0.001)then
write(*,*)"Initial choice",check+1.0
write(*,*)"The solution is"
write(*,*)x1
else
goto 19
endif
if(x1<10.0)goto 20
end
function f(q)
real::q
f=(q**2+6.0)/5.0
return
end function
real::x1,x2,check
x1=-1.5
check=x1
20 check=check+1.0
x1=check
19 x2=f(x1)
x1=x2
!write(*,*)check
if(abs(f(x2)-x2)<=0.001)then
write(*,*)"Initial choice",check+1.0
write(*,*)"The solution is"
write(*,*)x1
else
goto 19
endif
if(x1<10.0)goto 20
end
function f(q)
real::q
f=(q**2+6.0)/5.0
return
end function
Output:
Summary:
Comments
Post a Comment