Write a function find square root(x) that takes as input a number x and as output returns the square root of x. Your results should converge to at least 6 decimal places. matlab question
In case of any queries,please comment. I would be very happy to assist all your queries.Please give a Thumps up if you like the answer.
Program
function root = square_root(x)
format long
error = 0.0000001; %accuracy level
root = x;
while ((root - x / root) > error)
root= (root + x / root) / 2;
end
end
Output
square_root(16)
ans =
4.000000000000051
square_root(25)
ans =
5.000000000053722
Program Screenshot
Get Answers For Free
Most questions answered within 1 hours.