I already completed part (a) using simple algebra, but i am having trouble with
ID: 2966119 • Letter: I
Question
I already completed part (a) using simple algebra, but i am having trouble with part (b). Please show code and explain all steps. Thanks.
Suppose your hardware implements neither division nor inversion, only addition, subtraction, and multiplication. Use the iteration to calculate the inverse of a nonzero value a. Show that if r := xn = xn+i, i.e.. r is a fixed point of the iteration, then either r = 0 or r = 1/a. Write a function to implement this iteration. Specify a stopping criterion for arbitrary > 0 without performing any divisions or inversions.Explanation / Answer
function [inv]=inverse_1(a, x0)
% Approximate inverse (inv) of a number a starting from x0
x(1)=x0; % initial guess
n=1; % iteration counter
while (abs(x(n)-1/a)>eps) % until error <= epsilon
n=n+1;
x(n)=(2-a*x(n-1))*x(n-1);
end
inv=x(n);
-------------------------------------OUTPUT------------------------------------------
>> inverse_1(1,1)
ans =
1
----------------------------------
>> inverse_1(2,1)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.