choice= input('Enter a vector sufficent for an odd-order polynomial: ');
a=numel(choice);
C = 1;
while mod(a,2)~=0
C=C+1;
choice= input('Enter a vector sufficent for an odd-order polynomial: ');
if C == 5 && mod(a,2)~=0
warning('Odd number of coefficients entered. Last element removed');
choice(:,end)=[];
end
a=numel(choice);
end
while again == 1
guess=input('Enter an intial guess for the Newton Ralph method: ');
derv = polyder(choice);
b= polyval(derv,guess);
D=1;
while b==0
D=D+1;
derv = polyder(choice);
b= polyval(derv,guess);
guess=input('Enter an intial guess for the Newton Ralph method: ');
if D == 3 && b==0
error('Initial guess causes divide by 0. Program terminated');
end
end
percent_error = 0;
while percent_error<=0.1 || percent_error>=10
percent_error = input('Enter the percent difference to compute [0.1% - 10%]: ');
end
xn=guess-(polyval(choice,guess)./(polyval(polyder(choice),guess)));
Counter=1;
Val = [guess,xn];
while (abs(Val(Counter+1)-Val(Counter))/Val(Counter)).*100 > percent_error
Counter=Counter+1;
xn=Val(Counter)-(polyval(choice,Val(Counter))./(polyval(polyder(choice),Val(Counter))));
Val(Counter+1) = xn;
end
fprintf('The solution converged in %d iterations',Counter);
F= ["Yes","No"];
again = menu('Repeat newton rsphson calculation?',F);
if again == 2
end
end
2 Comments
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/508017-trying-to-get-when-i-say-yes-it-would-repeat-again-and-if-no-it-stops-the-loop-but-it-would-store-a#comment_803301
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/508017-trying-to-get-when-i-say-yes-it-would-repeat-again-and-if-no-it-stops-the-loop-but-it-would-store-a#comment_803301
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/508017-trying-to-get-when-i-say-yes-it-would-repeat-again-and-if-no-it-stops-the-loop-but-it-would-store-a#comment_803308
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/508017-trying-to-get-when-i-say-yes-it-would-repeat-again-and-if-no-it-stops-the-loop-but-it-would-store-a#comment_803308
Sign in to comment.