- #1
NicolasPan
- 21
- 2
The program must calculate the length of the curve of ƒ=3.1*x^2-5.3/x between x=1/2 and x=3/2.The legth should be calculated as the sum of n line segments starting with n=1 and ending with n=20.
I really can't find why the result I'm getting is wrong.Thanks in advance
I am giving you the code below:
I really can't find why the result I'm getting is wrong.Thanks in advance
I am giving you the code below:
Fortran:
program pr2_ex2
implicit none
integer::x
double precision::dy,dx !dy=the height of the linear part & dx=the length of the linear part
double precision::x1,x2,s !f=f(x) the function,x=the values which can be given to f
double precision::length
print*,"Please enter the function's starting point"
read*,x1
print*,"Please enter the function's ending point"
read*,x2
length=0
s=0
do x=2,21
dx=((x*abs(x2-x1)-(x-1)*abs(x2-x1))/(20))
dy=(3.1*(x*abs(x2-x1)/20)**2-(5.3*20/x*abs(x2-x1)))-(3.1*((x-1)*abs(x2-x1)/20)**2-(5.3*20/(x-1)*abs(x2-x1)))
length=sqrt((dx**2)+(dy**2))
s=length+s
end do
print*,s
end program
Last edited: