Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Numerical Methods for Finding Roots of a Polynomial Function, Exercises of Numerical Methods in Engineering

This document demonstrates the implementation of the secant method to find the root of a polynomial function using matlab. The function f(x) = x^3 - 2x - 5 is used as an example, and the secant method is applied iteratively to find the root with an accuracy of 10 iterations. The code prints out the root and the error at each iteration.

Typology: Exercises

2016/2017

Uploaded on 12/30/2017

rian-rivera
rian-rivera 🇵🇭

1 document

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
clc;
f=@(x) x^3-2*x-5;
a=2; b=3;
for i=1:10
x0=a; x1=b;
fprintf('\n Hence root lies between (%.4f,%.0f)',a,b)
x2(i)=x0-(x1-x0)/(f(x1)-f(x0))*f(x0);
if f(x2(i))>0
b=x2(i);
else a=x2(i);
end
fprintf('\n Therefore, x2=%.4f \n Here, f(x2)=%.4f',x2(i),f(x2(i)))
p=x2(i);
end
for i=1:10
error(i)=p-x2(i);
end
Answer=p

Partial preview of the text

Download Numerical Methods for Finding Roots of a Polynomial Function and more Exercises Numerical Methods in Engineering in PDF only on Docsity!

clc; f=@(x) x^3-2*x-5; a=2; b=3;

for i=1: x0=a; x1=b; fprintf('\n Hence root lies between (%.4f,%.0f)',a,b) x2(i)=x0-(x1-x0)/(f(x1)-f(x0))*f(x0); if f(x2(i))> b=x2(i); else a=x2(i); end fprintf('\n Therefore, x2=%.4f \n Here, f(x2)=%.4f',x2(i),f(x2(i))) p=x2(i); end for i=1: error(i)=p-x2(i); end Answer=p