MATLAB Code for Finding the Square Root using Bisection Method, Exercises of Calculus

This matlab code implements the bisection method to find the square root of a given number. The user sets the interval bounds and the number of iterations, and the code calculates the square root by repeatedly averaging the interval endpoints and checking which endpoint is the root. The process continues until the function value at the new endpoint is less than zero, indicating that the new endpoint is closer to the root than the previous one.

Typology: Exercises

2020/2021

Uploaded on 08/29/2021

isadora-martines
isadora-martines 🇨🇦

1 document

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
%% BISSECÇÃO %%
%% configuração MATLAB
format long
clc
clear
close all
%% entrada
x = -0.75; %%% menor valor do intervalo [x,X]
X = -0.25; %%%maior valor do intervalo
l = 1; %%%valor limite
%% Conta
for k = 1:l
Y = (x+X)/2;
%%f(a)
f = x^5-(10/9)*x^3+(5/21)*x;
%%f(y)
h = Y^5-(10/9)*Y^3+(5/21)*Y
if f<0
X = Y;
else
x = Y;
end
k = k+1;
end
Y

Partial preview of the text

Download MATLAB Code for Finding the Square Root using Bisection Method and more Exercises Calculus in PDF only on Docsity!

%% BISSECÇÃO %%

%% configuração MATLAB format long clc clear close all %% entrada x = -0.75; %%% menor valor do intervalo [x,X] X = -0.25; %%%maior valor do intervalo l = 1; %%%valor limite %% Conta for k = 1:l Y = (x+X)/2; %%f(a) f = x^5-(10/9)x^3+(5/21)x; %%f(y) h = Y^5-(10/9)Y^3+(5/21)Y if f< X = Y; else x = Y; end k = k+1; end Y