I wrote a function that uses the Newton-Raphson method to calculate the value of y for the following equations: x^2 + y^2 – 1 , x*y – 0.5 .
The output gives me the Results followed by ans = 11 (which im assuming is the number of iterations it took to converge.) How do I get rid of the "ans = " part?
The last y value converges to: 0.7071ans = 11function [result1,result2] = NR3()syms x yf1 = input('\nPlease Enter equation 1: ');f2 = input('\nPlease Enter equation 2: ');y0 = input('\nPlease Enter an initial y value: ');tol = input('\nPlease Enter a tolerance: ');f_x = solve(f2,x);f_y = subs(f1,x,f_x);dfdy = diff(f_y,y);d_w = [];yy_w = [];yy_w(1) = y0;tol1 = 100;i = 1;while tol1 > tol i = i + 1; d_w(i-1) = subs(f_y,y,yy_w(i-1))/subs(dfdy,y,yy_w(i-1)); yy_w(i) = yy_w(i-1) - d_w(i-1); tol1 = abs(yy_w(i) - yy_w(i-1));endformat longif isnan(yy_w(end)) result1 = fprintf('\nError: Divergence! '); result2 = fprintf('\nPlease try a different initial value. \n');else result1 = fprintf('\n\nResults\n\n'); result2 = fprintf('The y value converges to: %7.4f\n',yy_w(end));end end
Best Answer