Only MATLAB code is required. No handwritten solution is requested.
Use the Newton-Raphson method to determine a root of f (x) =− 0.9x2 + 1.7x + 2.5 using x0 = 5 . Perform the computation until ε a is less 0.01%. Verify the results with the plot. ( 25 pts. )
% Program Code of Newton-Raphson Method in MATLAB
X=1:0.1:10;
Y= -0.9*X.^2+1.7*X+2.5;
hold on;
grid on;
plot(X,Y);
a='-0.9*x^2+1.7*x+2.5';
x(1)=5;
error=0.0001;
f=inline(a);
dif=diff(sym(a));
d=inline(dif);
for i=1:10
x(i+1)=x(i)-((f(x(i))/d(x(i))));
err(i)=abs((x(i+1)-x(i))/x(i));
if err(i)<error
break
end
end
s=1:length(x);
plot(x(s),y(s),'*');
root=x(i);
fprintf('Root of given eqn is : %d\n',root);
notice that points get denser at x=2.86 closer to 3.
Kindly upvote please. ?
Get Answers For Free
Most questions answered within 1 hours.