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

Part 4: Newton\'s method (20 points) Most mathematically based problems introduc

ID: 3737436 • Letter: P

Question

Part 4: Newton's method (20 points) Most mathematically based problems introduced to you thus far have been solved u analytical solution, i.e. using the techniques learned in math and calculus to solve for an xact answer. However, many times in engineering an analytical solution may not exist for a problem or it may be too difficult to calculate. This then requires the use of numerical methods to find the solution. The following steps outline a basic numerical methods algorithm known as Newton's method for solving a mathematical equation. Make an initial guess: x Repeat until the difference between two guesses is less than a threshold, 1E-10 Plug guess into the equation: f (x) Plug the guess into the derivative of the equation: f' (x) Update you r guess: new guess guess - f(x) /f, (x) Determine the absolute difference between guess and new guess Update your guess to your new guess: guess new guess Use Newton's method to estimate the square root of a number with the following steps. Write all your answers in the table on the last page in the corresponding location. Prompt the user to input a number to find its square root from the command window. What command did you type? What was your initial guess for x? NOTE: x is not the number you are trying to find the square root of, x is a guess for the answer, i.e. xe Vnumber What kind of loop do you need to use to implement Newton's method? Does y loop need to run for a specified number of times or until a certain condition is met? 1. 2. 3.

Explanation / Answer

The complete code for the question is given below. Run the program for different inputs. Please do rate the answer if it helped. Thank you.

number = input('Enter the number whose square root is needed: ');
xnew = 0;
x = input('Enter your initial guess: ');
count = 0;
diff = abs(xnew - x);
while diff >= 1E-10
f = x^2 - number;
fdash = 2 * x;
xnew = x - f / fdash;
diff = abs(xnew - x);
x = xnew;
count = count + 1;
end

disp(['The square root of ', num2str(number), ' is ' , num2str(xnew)])
disp(['The no. of iterations is ' , num2str(count)])


==========
sample run
==========
Enter the number whose square root is needed: > 129
Enter your initial guess: > 11
The square root of 129 is 11.3578
The no. of iterations is 4

--------------
Enter the number whose square root is needed: > 1843
Enter your initial guess: > 40
The square root of 1843 is 42.9302
The no. of iterations is 5

--------
Enter the number whose square root is needed: > 75
Enter your initial guess: > 8
The square root of 75 is 8.6603
The no. of iterations is 5

*********************************************************************************
Answers for the questions 1 to 5
*********************************************************************************
1. number = input('Enter the number whose square root is needed: ');

2. Initial guess is a number for which we easily now the square such that it's square is less than the number. So for 129, the initial guess is 11, for 1849, the initial guess is 40 and for 75 it is 8

3. while loop is used since we want it to iterate until a specified condition is met. The loop used is
while diff >= 1E-10

4.
a) f = x^2 - number;
b) fdash = 2 * x;
c) xnew = x - f / fdash;
d) diff = abs(xnew - x);
e) x = xnew;
g) count = count + 1;


5.
a) for number = 129, the square root is 11.3578 and took 4 iterations
b) for number = 1845, the square root is 42.9302 and took 5 iterations
c) for number = 75, the square root is 8.6603 and took 5 iterations