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

please help me find the MATLAB code for this problem. Thank you! Newton\'s metho

ID: 3790233 • Letter: P

Question

please help me find the MATLAB code for this problem. Thank you!

Newton's method for solving f(x) = 0 draws the tangent to the graph of f(x) at any point and determines where the tangent intersects the x-axis. The method requires one starting value, x_0. The iteration is x_n + 1 = x_n - f (x_n)/f'(x_n) When Newton's method converges, it is very effective as it exhibits quadratic convergence: the error is roughly squared with each iteration - or the number of correct digits approximately doubles with each iteration. Using f(x) = x^2 - 3, program the Newton method with a maximum number of iterations equal to 50 and a convergence criterion |x_n + 1 - x_n| lessthanorequalto 10^-14 |x_n + 1| Set x_0 = 1. Save the four iterates [x_1, x_2, x_3, x_4]^T as a column vector in A07.dat. Save the number of iterations to reach convergence in A08.dat. The Newton method does not always converge. Consider the function f(x) = sign (x - 2) Squareroot |x - 2| with a starting value x_0 = 3. The derivative f' satisfies f'(x)/f(x) = 1/2(x - 2) It is essential that you test for a maximum number of iterations (for example, 50) and a convergence criterion: |x_n + 1 - x_n| lessthanorequalto 10^-14 |x_n + 1| Save the 5 iterates [x_1, x_2, x_3, x_4, x_5]^T as a column vector in A09.dat.

Explanation / Answer

% remove blank cells matlab centroids = centroids_test2'; centroids(cellfun(@isempty,centroids)) = [];

    % convert the contents of a cell array into a single matrix.
    centroid =[cell2mat(centroids')];      
    % find mean value                                 
    mean_centroid = round(mean(centroid));  
    % x coordinates of cenroid                                 
    centroid_x = centroid(:,1);  
    % y coordinates of cenroid                                           
    centroid_y = centroid(:,2);  
    %find x values more than mean                                         
    index1 = find(repmat(mean_centroid(1),length(centroid),1) < centroid_x);
    % find y values less than mean  
    index2 = find(repmat(mean_centroid(2),length(centroid),1) > centroid_y);
    Common_centroids = [centroid_x(index1),centroid_y(index2)];