how can i solve nonliner equation?

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

Show us what have you tried and why it didn't work..
  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

roots for solve nonliner equation?
Your equation is a 2nd order polynomial, with coefficients o f 1, -1 and 1:
>> coeffs = [1 -1 1];
>> roots(coeffs)
ans =
0.5000 + 0.8660i
0.5000 - 0.8660i
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!