Posts

Showing posts with the label Coding

Forecasting with ARIMA: R Code

Step-1:  ###R Packages Installed library(fpp2) library(readxl) library(SPlit) library(fpp2)   ###Declare time-series data ###In this study I have file naming as HPI_AUS. All the date excel format. HPI_AUS <-ts(AUSHPI[,2], start=c(2002,3), frequency=4)   Step-3: ###While forecasting, first that should be done within the sample, and if it is found valid, then only we forrecast out of sample. ###Split the given data into the training and test sets split_HPI_AUS <- ts_split(ts.obj = HPI_AUS, sample.out= 8) training <- split_AUSHPI$train testing <- split_AUSHPI$test length(training) length(testing)  Step-4:###Select the appropriate forecasting tool. Here I have used ARIMA (easy and quick model) ###ARIMA In-sample testing arima_diag(training)     ###Model forecasting In-sample arima1 <- auto.arima(training, seasonal= TRUE) autoplot(arima1) check_res(arima1)   ###Forecasting In-sample fcast1...

Golden Section Search Method: Fortran f90

Consider the nonlinear equation f(x)=4x 2 –exp(x). Write a Fortran program that uses the Golden Section Search Method to find the solution accurate to within 10 -6 for the nonlinear equation on [4,8].  Sauce Code: Program  Assignmentq2 implicit none real:: f real::x, r, q1, q2,a, b, tol=1.0e-6 !Define Interval and Function f(x) = 4*x**2-exp(x) a=4 b=8 print*, "a", a, "b", b !Evaluation of the function at the end point r=(sqrt(5.0)-1)/2 q1=b-r*(b-a) q2=a+r*(b-a)  print*, "q1",q1, "q2", q2  ! Creating Loop !if ((b-a)<=tol) stop do while ((b-a)>tol)      !if(f(a)*f(b)<=0) then      if(f(a)*f(q2)<=0) then          b=q2          q2=q1          q1=b-r*(b-a)      else          a=q1          q1=q2          q2=a+r*(b-a) ...

Gaussian Elimination Method: Fortran f90

 Question: Solve the following system of linear equations using Gaussian Elimination using Fortran. x 1 + x 2 - x 3 + x 4 - x 5 = 2 2x 1 + 2 x 2 + x 3 - x 4 + x 5 = 4 3x 1 + x 2 -3 x 3 -2x 4 + 3 x 5 = 8 4x 1 + x 2 - x 3 +4 x 4 -5x 5 =16 16x 1 -x 2 + x 3 - x 4 - x 5 =32   Solution: program main implicit none integer, parameter :: n=5 double precision:: a(n,n), b(n), x(n) integer:: i,j ! matrix A   data (a(1,i), i=1,5) /  1.0,  1.0,  -1.0, 1.0, -1.0 /   data (a(2,i), i=1,5) /  2.0,  2.0,  1.0, -1.0, 1.0 /   data (a(3,i), i=1,5) /  3.0,  1.0,  -3.0, -2.0, 3.0 /   data (a(4,i), i=1,5) /  4.0,  1.0,  -1.0, 4.0, -5.0 /   data (a(5,i), i=1,5) /  16.0, -1.0, 1.0, -1.0, -1.0 / ! matrix b   data (b(i),   i=1,5) /  2.0, 4.0, 8.0, 16.0, 32.0 / ! print a header and the original equations   write (*,200)   do i=1,n      write ...