Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help me with writing a code in Fortran builder 6.1, I also need to plot t

ID: 3874960 • Letter: P

Question

Please help me with writing a code in Fortran builder 6.1, I also need to plot the intrinsic function and data points in techplot 360 which I think I can handle with just the code. I am very inexperienced in Fortran and any comments made throughout the code would be greatly appreciated. Thanks!

The Taylor series of a real or complex-valued function fix) that is infinitely differentiable at a real or complex number a is the power series f"(a) f"(a) 2! f (a) 3! where n! denotes the factorial of n and f (a) denotes the nth derivative of f evaluated at the point a. Modify the program we have discussed in the class to approximate the function Log(1+x) for x between -1.5 and 1.5. You may choose an interval of 0.1 to plot the function. Compare your solution with the real function using Tecplot for n 2 and 4. Hints:

Explanation / Answer

The following program takes a real value x as input and computes the value of log(1+x) using taylor series expansion. It also prints out the expected value for the function for a given value of x for comparative plotting. This can be run for different values of x to plot the calculated versus actual values.

Fortran code:

-----------------

program logtest
implicit none
real :: x = 0
real :: y = 0
integer :: sgn, i

sgn = 1
print*,"enter the value of x in log(1+x)"
read (*,*) x

y = 0
do i = 1, 10, 1
y = y + sgn * x**i / i
sgn = -sgn
end do
  
print *, 'Calculated value: ',y,'Actual value: ',log(1+x)

end program logtest

-------------------------------------------------------------------------------------------------------------------------------

Test results with different values of x:

e.g.,

For x=0.25   

calculated value of log(1+x)= 0.223143518 , Actual value= 0.223143548

For x=0.5   

calculated value of log(1+x)= 0.405434638, Actual value= 0.405465096

For x=1.0

calculated value of log(1+x)= 0.645634890 , Actual value= 0.693147182

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote