Question: This is the 4th HW assignment. This time our subject is integration (numerical) and the subroutine is coming from Ch 4, namely Gauss-Legendre Integration code:

This is the 4th HW assignment. This time our subject is integration (numerical) and the subroutine is coming from Ch 4, namely Gauss-Legendre Integration code: gauleg.f90. You would need an external Func(x) in your code where your integration function is written. This is f(x)=x^2, exactly just like the examples we did in the class. I also share them with you here.
So now, please write a main function (just on FORTRAN) to call this gauled.f90 which also calls Func.f90 and calculate our simple reference integral of x^2 between 0 to 5 which will definetly be : 41.66666 !
 This is the 4th HW assignment. This time our subject is
integration (numerical) and the subroutine is coming from Ch 4, namely Gauss-Legendre

SUBROUTINE gauleg(Func, x1,x2,x,w,n) INTEGER :: n REAL :: Func, x1,x2,x(n),w(n) DOUBLE PRECISION EPS PARAMETER (EPS =3,d14) INTEGER : i,j,m DOUBLE PRECISION p1,p2,p3,pp,xl,xm,z,z1 External Func; m=(n+1)/2xm=0.5d0(x2+x1)xl=0.5d0(x2x1)do12i=1,mz=cos(3.141592654d0(i.25d0)/(n+.5d0)) 1 continue p1 =1,d0 p2 =0.d0 do 11j=1,n p3=p2 p2=p1 11 continue pp=n(zp1p2)/(zz1.d0) zl=z z=z1p1/pp if(abs(z-zl).gt.EPS)goto 1 x(i)=xmxlz x(n+1i)=xm+xlz w(i)=2.d0xl/((1.d0zz)ppppp) w(n+1i)=w(i) 12 continue return END SUBROUTINE gauleg float FUNC(float x ) \{ //return xx; //the integral for x2; It is analogly equal to : (1/3)(5^313)=(1/3)124=41.3333 return pow (x,2) \}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!