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

problem 9.13 Use a for loop determine the cost of a 4-vear education, assuming t

ID: 3558295 • Letter: P

Question

problem 9.13

Use a for loop determine the cost of a 4-vear education, assuming that the current cost for 1 year at a state school is $5000. use an if statement to compare your results from the previous two problems. Are you saving enough? Send an appropriate message to the command window. Edmand Hailey (the astronomer famous for discovering Hailey's comet) invented a fast algorithm for computing the square root of a number, A. Hailey s algorithm approximates as follows: Start with an initial guess Xj. The new approximation is then given by These two calculations are repeated until some convergence criterion, s, is met. Write a MATLAB function called my_sqrt that approximates the square root of a number. It should have two inputs, the initial guess and the convergence criterion. Test your function by approximating the square root of 5 and comparing it to the value calculated with the built-in MATLAB® function, sqrt.

Explanation / Answer

MALAB code :

function [ y ] = my_sqrt( xi, e )
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here

A = 4;
x_n1 = xi;
x_n = 0;
iter=0;
while(abs(x_n1 - x_n) > e)
x_n = x_n1;
y = x_n * x_n / A ;
x_n1 = (x_n/8)*(15 - y*(10-3*y));
iter = iter+1;
end

y = x_n1;

end