Question

In: Computer Science

Use a fixed-point iteration to determine the solution (in [0,1])ofthe equation x = 1.5cos(x). Use a...

Use a fixed-point iteration to determine the solution (in [0,1])ofthe equation x = 1.5cos(x). Use a starting value of 0.5. How many iterations does it take before you have an answer which is accurate in the first 2 digits? ...in the first 3 digits?...in the first 4 digits? What happens if you change the starting value to 0.7?...to 0.0?

Does the fixed-point iteration converge? If not, modify the equation so that x = cos(x)/30 + 44x/45. Does the iteration converge now?

Please code in R programming language with comments !
Thank you!!!
will upvote!!

Solutions

Expert Solution

ANSWER:

I have provided the properly commented and indented code so you can easily copy the code as well as check for correct indentation.
I have provided the output image of the code so you can easily cross-check for the correct output of the code.
Have a nice and healthy day!!

CODE

# function fixedPoint
fixedPoint <- function(f, xinit, tol = 1e-06, itmax = 10000) {
  # defining variable xold and initializing it with x initial
  xold <- xinit
  # calculating iterations
  itel <- 1
  # repeat loop, returning value when passes tolerance or max iter
  repeat {
    # fetching value of f w.r.t x old and assigning value to xnew
    xnew <- f(xold)
    # xold and new difference passes tolerance, returning value
    if ((max(abs(xold - xnew)) < tol) || (itel == itmax)) {
      # passing xnew and # of iterations
      return(c(xnew,itel))
    }
    # otherwise, initializing xold to xnew and incrementing loop counter
    xold <- xnew
    itel <- itel + 1
  }
}

# a. 1.5*cos(x), xinit = 0.5
# defining function 1.5*cos(x)
fun <- function(x) return(1.5*cos(x))
# accurate sol in first 2 digit
fst2 <- fixedPoint(fun,0.5,1e-02)
# priniting result and iteration
cat("first 2 digits accurate: ",fst2[1],"\nfirst 2 digits accurate iterations: ",fst2[2])

# accurate sol in first 3 digit
fst3 <- fixedPoint(fun,0.5,1e-03)
# priniting result and iteration
cat("first 3 digits accurate: ",fst3[1],"\nfirst 3 digits accurate iterations: ",fst3[2])

# accurate sol in first 4 digit
fst4 <- fixedPoint(fun,0.5,1e-04)
# priniting result and iteration
cat("first 4 digits accurate: ",fst4[1],"\nfirst 4 digits accurate iterations: ",fst4[2])

# starting value to 0.7
# accurate sol for start 0 digit
strt0 <- fixedPoint(fun,0,1e-03)
# priniting result and iteration
cat("start 0, x value: ",strt0[1],"\nstart 0, x iterations: ",strt0[2])

# accurate sol for start 0.7 digit
strt7 <- fixedPoint(fun,0.7,1e-03)
# priniting result and iteration
cat("start 0.7, x value: ",strt7[1],"\nstart 0.7, x iterations: ",strt7[2])

print("Iteration has not converged till now!")

# b for function cos(x)/30 + 44x/45
print("For eqn cos(x)/30 + 44*x/45")
fun <- function(x) return(cos(x)/30 + 44*x/45)
# accurate sol in first 2 digit
fst2 <- fixedPoint(fun,0.5,1e-02)
# priniting result and iteration
cat("first 2 digits accurate: ",fst2[1],"\nfirst 2 digits accurate iterations: ",fst2[2])
print("Iteration converged for this!")

OUTPUT IMAGE


Related Solutions

For the equation e^x =x+2, (a) use the fixed point iteration method to determine its two...
For the equation e^x =x+2, (a) use the fixed point iteration method to determine its two roots to eight correct decimal places (you may need to write this equation in two different ways of x = g(x) in order to obtain these two roots); (b) numerically calculate the convergence rates for your converged iterations; (c) compare these numerical convergence rates with the theoretical conver- gence rates we presented in class (also see Theorem 1.6 on page 38 of the textbook).
Use the Fixed-Point Iteration Method to find the root of f ( x ) = x...
Use the Fixed-Point Iteration Method to find the root of f ( x ) = x e^x/2 + 1.2 x - 5 in the interval [1,2].
Prove that equation have a unique solution through the point (0,1). With the knowledge acquired can...
Prove that equation have a unique solution through the point (0,1). With the knowledge acquired can you exhibit explicitly that unique solution for a and b? (a) y' = y - y^2 (b) y' = y^2 - y^3
Create a python code that calculates fixed point iteration method using a for loop.
Create a python code that calculates fixed point iteration method using a for loop.
Determine a differential equation that has x = 0 as a regular singular point and that...
Determine a differential equation that has x = 0 as a regular singular point and that the roots of the index equation are i and i. Find a solution around x = 0.
For the following exercises, solve the equation for x, if there is a solution. Then graph both sides of the equation, and observe the point of intersection (if it exists) to verify the solution. log3 (x) + 3 = 2
For the following exercises, solve the equation for x, if there is a solution. Then graph both sides of the equation, and observe the point of intersection (if it exists) to verify the solution.log3 (x) + 3 = 2
Plot the Trapezoid Method approximate solution on [0,1] for the differential equation y = 1 +...
Plot the Trapezoid Method approximate solution on [0,1] for the differential equation y = 1 + y2 and initial condition (a) y0 = 0 (b) y0 = 1, along with the exact solution (see Exercise 6.1.7). Use step sizes h = 0.1 and 0.05 (Code In Matlab)
Plot the Euler’s Method approximate solution on [0,1] for the differential equation y* = 1 +...
Plot the Euler’s Method approximate solution on [0,1] for the differential equation y* = 1 + y^2 and initial condition (a) y0 = 0 (b) y0 = 1, along with the exact solution (see Exercise 7). Use step sizes h = 0.1 and 0.05. The exact solution is y = tan(t + c)
Use the Method of Variation of Parameters to determine the general solution of the differential equation...
Use the Method of Variation of Parameters to determine the general solution of the differential equation y'''-y'=3t
Use the method of variation of parameters to determine a particular solution to the given equation....
Use the method of variation of parameters to determine a particular solution to the given equation. y′′′+27y′′+243y′+729y=e^−9x yp(x)=?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT