
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
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
1 / 1
This page cannot be seen from the preview
Don't miss anything!
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