0% found this document useful (0 votes)
16 views7 pages

EXP8

The document outlines an experiment focused on solving the nonlinear equation y=x^3-5*x+1 using numerical methods such as Bisection, Regula Falsi, and Newton-Raphson in both SCILAB and Python. It discusses the algorithms, implementation, and comparative analysis of the methods, highlighting their strengths and weaknesses in terms of reliability and speed. The conclusion emphasizes the importance of selecting the appropriate method based on problem specifics and desired accuracy.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views7 pages

EXP8

The document outlines an experiment focused on solving the nonlinear equation y=x^3-5*x+1 using numerical methods such as Bisection, Regula Falsi, and Newton-Raphson in both SCILAB and Python. It discusses the algorithms, implementation, and comparative analysis of the methods, highlighting their strengths and weaknesses in terms of reliability and speed. The conclusion emphasizes the importance of selecting the appropriate method based on problem specifics and desired accuracy.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

EXPERIMENT NO – 08

NON-LINEAR EQUATION IN SCILAB AND PYTHON


AIM:

To develop Algorithm for solving a equation using the above method and the given equation is
y=x^3-5*x+1 to solve by different methods like bisection, Regulafalsi and Newton Raphson.

OBJECTIVE:

solving equation using different method and analyizing it and getting different output for
different input values.

PROBLEM STATEMENT:

Basically developing an algorithm for solving the given equation by various methods and for
different input values to get different output values.

THEORY:

When traditional analytical math falls short, numerical methods step in to provide practical,
approximate solutions for complex problems. These techniques are essential tools in fields like
engineering, physics, and computer science for determining the roots of nonlinear functions—
the specific x-values where a given equation, such as f(x) = x^3 - 5x + 1, evaluates to zero. To
tackle these otherwise unsolvable equations, mathematicians and engineers frequently rely on
foundational root-finding algorithms like the Bisection, Regula Falsi, and Newton-Raphson
methods.

Both the Bisection and Regula Falsi approaches rely on the Intermediate Value Theorem,
requiring an initial interval where the function's sign flips to guarantee a root exists. The
Bisection Method takes the most straightforward route by continuously cutting this interval in
half to isolate the root, offering guaranteed but gradual convergence. In contrast, the Regula
Falsi (or False Position) Method attempts to accelerate the search by drawing a straight line
between the interval's boundary points and using that line's x-intercept as the next guess. While
generally faster, Regula Falsi can occasionally stall if one end of the interval gets stuck during
the iterations.

Taking a fundamentally different approach, the Newton-Raphson Method relies on calculus


rather than bracketing intervals. It begins with a single initial guess and uses the function's first
derivative to draw a tangent line; the point where this tangent crosses the x-axis becomes the
next approximation. While this technique boasts remarkably fast convergence when the initial
guess is close to the true root, it is also more fragile and can fail entirely if the starting guess is
too far off or if the derivative happens to be zero.

ALGORITHM:

1. Start.
2. Define the Function: f(x)= x - 5x + 1and its derivative f'(x) = 3x – 5.
3. Input: Enter initial guesses a, b and the number of iterations n.
4. Validation: If f(a).f(b) > 0, display "Change the initial guesses".
5. Iteration Loop:

6. Calculate the new root approximation c based on the selected method.

7. Check if the change between iterations |d - c| is less than 0.0001; if yes, break the
loop.

8. Output: Print the final root approximation and the iteration count.
9. End.

PYTHON(INPUT)
#solving numerical methods of non linear equation using bisection
method and regulafalsi
def f(x):
return x**3-5*x+1
a=float(input('Enter value of a'))
b=float(input('Enter vlue of b'))
n=int(input('Enter the number of iterations'))
fa=f(a)
fb=f(b)
if (fa*fb) > 0 :
print('Change the initial gueses')
exit()
d=0
for i in range (1,n+1):
c=(a+b)/2 #Bisection
# c=(fa*b)-(a*fb)/(fa-fb) R-F
fc=f(c)
if fc < 0 : #Bisection and R-F
a=c # Bisection and R-F
fa=fc # Bisection and R-F
else : #Bisection and R-F
b=c #Secant,Bisection and R-F
fb=fc #Secant,Bisecion and R-F
if abs(d-c) < 0.0001:
d = c
break
print("Iteration & Root Approximation = ",c)

#solving numerical methods of non linear equation using Newton


Raphson method
def f(x):
return x**3-5*x+1
def df(x):
return 3*x**2-5

a=float(input('Enter value of a'))


b=float(input('Enter vlue of b'))
n=int(input('Enter the number of iterations'))
fa=f(a)
fb=f(b)
d=0
if(fa*fb) > 0 :
print('Change the initial gueses')
exit()

if(fa+fb) > 0 :
x=a
else:
x=b
for i in range(1,n+1):
x=x-(f(x)/df(x))
if abs(d-x)<0.0001 :
break

d=x

print('Intration=',i)
print('Root = ',x)

SCILAB(INPUT)

//To develop an Algorithm in SCILAB and PYTHON for numericalmethod


of solving non linear equations by bisection,regula falsi
clc;clear
function y=f(x)
y=x^3-5*x+1
endfunction
a=input('Enter value of a')
b=input('Enter vlue of b')
n=input('Enter the number of iterations')
fa=f(a);fb=f(b)
if (fa*fb) > 0 then
error('Change the initial gueses')
end
d=0
for i=1:n
c=(a+b)/2 //Bisection
//c=(fa*b)-(a*fb)/(fa-fb) //R-F and Secant
fc=f(c)
if fc<0 then // Bisection and R-F
a=c // Bisection and R-F
fa=fc // Bisection and R-F
//a=b //Secant
//fa=fb //Secant
else //Bisection and R-F
b=c //Secant,Bisection and R-F
fb=fc //Secant,Bisecion and R-F
if abs(d-c)<0.0001
break
end
d=c
end
end
disp("Iteration & Root Approximation",[i,c])

// NEWTON RAPHSON METHOD


clc;clear
function y=f(x)
y=x^3-5*x+1
endfunction
a=input('Enter value of a')
b=input('Enter vlue of b')
n=input('Enter the number of iterations')
fa=f(a)
fb=f(b)
d=0
if(fa*fb)>0 then
error('Change the initial gueses')
end
if(fa+fb)>0 then
x=a
else
x=b
end
for i=1:n
x=x-(f(x)/numderivative(f,x))
if abs(d-x)<0.0001 then
break
end
d=x
end
disp(i,x)

OUTPUT(PYTHON)

1.
Enter value of a2

Enter value of b4

Enter the number of iterations6

Iteration & Root Approximation = 2.15625

2.
Enter value of a2

Enter value of b4

Enter the number of iterations6

Iteration= 4

Root = 2.1284190638445777

OUTPUT(SCILAB)
1.
Enter value of a2

Enter value of b4

Enter the number of iterations6

"Iteration & Root Approximation"

6. 2.15625

2.
Enter value of a2
Enter value of b4

Enter the number of iterations6

4.

2.1284191

DISCUSSION:

In this comparative analysis of three root-finding algorithms applied to a single equation, the
Bisection Method emerged as the most dependable, albeit the most time-consuming. Because
it systematically halves the interval without factoring in the function's curve, it naturally
requires a higher number of iterations to achieve the target accuracy. Nevertheless, its
foolproof, guaranteed convergence and straightforward logic make it an excellent baseline tool,
particularly for novices or scenarios where absolute stability is the top priority.

The other two techniques prioritized speed but introduced unique vulnerabilities. The Regula
Falsi Method generally outpaced Bisection by utilizing linear interpolation to estimate the root,
though it occasionally suffered from stagnation when an interval endpoint remained stuck,
making it a slightly less reliable middle-ground option. Meanwhile, the Newton-Raphson
Method proved to be the swiftest overall by leveraging derivative calculations to rapidly
pinpoint the root. However, this blistering speed is entirely contingent on a highly accurate
initial guess; a poor starting point can easily cause the equation to diverge or fail entirely.

Ultimately, selecting the ideal numerical method requires balancing speed against
mathematical safety. While Bisection guarantees a result at the cost of computational time,
Regula Falsi offers a moderate compromise, and Newton-Raphson delivers maximum
efficiency alongside a higher risk of failure. The optimal choice will always come down to the
specific nature of the problem, the required level of precision, and the available computational
resources.
CONCLUSION:

This experiment highlights the vital role of numerical analysis in solving complex
nonlinear equations that resist traditional analytical solutions. By evaluating the
Bisection, Regula Falsi, and Newton-Raphson techniques, we gained valuable insight
into their practical mechanics and individual strengths. The Bisection method stands out
for its unwavering reliability; as long as the initial interval correctly brackets the root, it
guarantees convergence. While this methodical pace requires more iterations, its
stability makes it an excellent educational tool. The Regula Falsi method generally
outpaces Bisection by employing a more sophisticated approximation strategy to reduce
iterations, though its convergence speed can occasionally become erratic depending on
how the function behaves near the chosen boundaries.

Conversely, the Newton-Raphson method proved to be the fastest and most computationally
efficient technique of the group. However, its rapid convergence is highly conditional,
requiring both the calculation of the function's derivative and a precise initial guess to avoid
errors. Ultimately, this comparison demonstrates that no single numerical method is universally
superior. The optimal choice will always depend on a careful assessment of the specific
problem, requiring a balance between the desired computational speed, the necessary accuracy,
and the mathematical information available.

You might also like