ME021- Engineering Computing-Spring 2018 the arrays. You may assume there will a
ID: 3721927 • Letter: M
Question
ME021- Engineering Computing-Spring 2018 the arrays. You may assume there will always be two header lines, but there could be any number of data lines .Set up a loop where: The data is shown on the console with a line number for each line. For larger data sets, this may cause the console to scroll, which is fine. The user is asked if there is a data point to be removed. If there is, then remove it from the arrays. This may require allocating temporary arrays and allocating the data arrays again. You will need to use the deallocate function before allocating an array that has already been allocated. Choose how to set up the prompts for this to make sense to the user If the user chose not to remove a data point, exit the loop. o o o Compute the averages and the best-fit slope and intercept, per the relations above. Print the resulting equation for the best-fit line in a tidy format that uses engineering notation. . Plan on spending some time on this data point removal requirement. It will require some thinking about how the loop should run, when it should check to leave the loop, and so on. It may be helpful to initially set up the loop with no removal working, just to get it to print properly and get the user's input. Then, get it to remove the chosen data point, which there are several ways to do. Your program should run for any length data file, without assuming a maximum length anywhere. Three data files (xydata1.txt, xydata2.txt, and xydata3.txt) are provided on CatCourses for testing, and your TA may choose to use others as well Sample Run To help visualize what the program will look like when running, a sample run is shown below. The sample data file used xydata.txt is also available on CatCourses Enter the data file nane: xydata.txt The following 5 data points were read from xydata.txt data pointxvalue y value 0.2304 5.2995 10.3687 15.4378 520.569 5.5563 e.1252 24.6106 19.8167 Choose a point to delete or to keep this data: 2 The following 4 data points were read from xydata.txt data point value 0.2304 10.3687 15,4378 420.5e69 y value 40.2611 0.1252 24.6186 19.8167 Choose a point to delete or e to keep this data: e We find the equation of the line to be y 1.014x40.584Explanation / Answer
As my best of Knowledge and working Experience the below is the desired code
parameter(SIZE=25)
integer i,ij,j,k,n,n1,m,m1,m2
real*8 C(SIZE,SIZE)
real*8 A(SIZE),B(SIZE),X(SIZE),Xc(SIZE),Y(SIZE),Yx(SIZE)
real*8 p,xx,s,yc
write(*,10,advance='no'); read *, n
n=n-1
write(*,20,advance='no'); read *, m
n1=n+1; m1=m+1; m2=m+2
print *,' '
print *,' Function to approximate:'
do i=1, n1
if (i<10) then
write(*,30,advance='no') i, i
else
write(*,31,advance='no') i, i
end if
read *, X(i), Y(i)
end do
do k=1, m2
Xc(k)=0.d0
do i=1, n1
Xc(k) = Xc(k) + X(i)**k
end do
end do
yc=0.d0
do i=1, n1
yc = yc + Y(i)
end do
do k=1, m
Yx(k)=0.d0
do i=1, n1
Yx(k) = Yx(k) + Y(i)*X(i)**k
end do
end do
do i=1, m1
do j=1, m1
ij=i+j-2
if (i==1.and.j==1) then
C(1,1) = n1
else
C(i,j)=Xc(ij)
end if
end do
end do
B(1)=yc;
do i=2,m1
B(i)=Yx(i-1)
end do
do k=1, m
do i=k+1, m1
B(i) = B(i) - C(i,k)/C(k,k)*B(k)
do j=k+1, m1
C(i,j) = C(i,j) - C(i,k)/C(k,k)*C(k,j)
end do
end do
end do
A(m1)=B(m1)/C(m1,m1)
do i=m, 1, -1
s=0.d0
do k=i+1, m1
s = s + C(i,k)*A(k)
end do
A(i) = (B(i)-s)/C(i,i)
end do
print *,' '
write(*,40) m, n+1
print *,' Coefficients of polynomial:'
do i=1, m1
write(*,50) i-1, A(i)
end do
print *,' '
print *,' Approximated function:'
print *,' X Y '
do i=1, n1
xx=X(i); p=0.d0
do k=1, m1
p = p*xx + A(m1+1-k)
end do
write(*,60) xx, p
end do
print *,' '
print *,' '
10 format(/' Number of points : ')
20 format(/' Degree of polynomial: ')
30 format(' X(',I1,'), Y(',I1,') = ')
31 format(' X(',I2,'), Y(',I2,') = ')
40 format(' Polynomial approximation of degree ',I2,' (',I2,' points)'/)
50 format(' A(',I,') = ',F15.9)
60 format(2F12.6)
end
! end of file approx.f90
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.