how can i solve nonliner equation?

1 view (last 30 days)
I tryed to find roots of nonliner equation by use all posible codes: fsolve, fzero, fixed pointes, raphson method.
Equation is: x^2-x+1.
Help me.
  2 Comments
KSSV
KSSV on 18 Oct 2020
Show us what have you tried and why it didn't work..
Mariam Sordia
Mariam Sordia on 18 Oct 2020
  1. Raphson method:
clc
clear all
x0=1;
x=x0;
xold=x0;
iter=50;
round=1e-6;
for i=1:iter
f=x^2-x+1;
df=2*x-1;
x=x-f/df
err=abs(x-xold)
xold=x
if err<round
break
end
end

Sign in to comment.

Accepted Answer

Alan Stevens
Alan Stevens on 18 Oct 2020
look at documentation on the "roots" function, (ie type help roots).
  4 Comments
Alan Stevens
Alan Stevens on 18 Oct 2020
Notice that the roots are complex, which is why your Newton Raphson code didn't work. Try setting x0 = 1+1i in your code.

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!