Hi, guys!
I have to write a console application that tabulate a function in a given interval. This is the code I wrote:
program Calculate_Function
real, dimension(0:200) :: x, y
real :: a, b, h, n
character(len=32) :: file_name
print *, "Input the name of the file: "
read *, file_name
open(unit = 5, file = file_name, action = "write", status = "new")
print *, "Input range of the interval:"
print *, "a = "
read *, n
print *, "b = "
read *, b
print *, "Input step h = "
read *, h
write(unit = 5, fmt = *) " x(i)", " y(x(i))"
do a = n, b, h
y(a) = x(a)** + 2*sin(x(a)) + 4
write(unit = 5, fmt = *) x(a), y(a)
end do
close(unit = 5)
end program Calculate_Function
I don't know how to do the "do" loop so that it calculates the value of the function of each step.
I have to write a console application that tabulate a function in a given interval. This is the code I wrote:
program Calculate_Function
real, dimension(0:200) :: x, y
real :: a, b, h, n
character(len=32) :: file_name
print *, "Input the name of the file: "
read *, file_name
open(unit = 5, file = file_name, action = "write", status = "new")
print *, "Input range of the interval:"
print *, "a = "
read *, n
print *, "b = "
read *, b
print *, "Input step h = "
read *, h
write(unit = 5, fmt = *) " x(i)", " y(x(i))"
do a = n, b, h
y(a) = x(a)** + 2*sin(x(a)) + 4
write(unit = 5, fmt = *) x(a), y(a)
end do
close(unit = 5)
end program Calculate_Function
I don't know how to do the "do" loop so that it calculates the value of the function of each step.