0% found this document useful (0 votes)
15 views8 pages

Nı Nümerik

This document contains MATLAB code to find the root of a function f(x) using the bisection method. It defines the function, plots it, then applies the bisection method iteratively between x limits of 140 and 150 to find a root. It stores and displays the results, finding a root of 149.99 after 19 iterations with an error of 0.0099.

Uploaded by

Yusuf Yildiz
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)
15 views8 pages

Nı Nümerik

This document contains MATLAB code to find the root of a function f(x) using the bisection method. It defines the function, plots it, then applies the bisection method iteratively between x limits of 140 and 150 to find a root. It stores and displays the results, finding a root of 149.99 after 19 iterations with an error of 0.0099.

Uploaded by

Yusuf Yildiz
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
You are on page 1/ 8

SORU 1

SORU 2
clc;close all;clear all;

% Plot function f(x)


t=4;
x=50:1:200; %%%%%%% Mass of the bungee jumper
g=9.81;
cd=0.25;
v=36;
f = sqrt(g.*x/cd).tanh(sqrt(gcd./x)*t)-v; %%%%%%% The function
f(x)i.e. f(m)
plot(x,f,'b','LineWidth',3); %%%%Plot the function
title('f(m) = sqrt(g.*x/cd).tanh(sqrt(gcd./x)*t)-v')
xlabel('mass(kg)')
ylabel('f(m)')

% Bisection Method's
xl = 140; % Lower limit of the closed interval
xu = 150; % Upper limit of the closed interval
fx =@(x) sqrt(g.*x/cd).tanh(sqrt(gcd./x)*t)-v; % Define the function
f(x)
es = 0.01; % Given approximate absolute relative error tolerance.
imax = 100; % Define maximum # iteration
xl_all = []; % Store all calculated values of xl
xu_all = []; % Store all calculated values of xu
xr_all = []; % Store all calculated values of xr
ea_all = []; % Store all calculated values of ea
fxl_all = []; % Store all calculated values of f(xl)
fxu_all = []; % Store all calculated values of f(xu)
fxr_all = []; % Store all calculated values of f(xr)
if fx(xl)*fx(xu) > 0 % if guesses do not bracket
disp('no bracket')
return
end

for i=1:1:imax
xr=(xu+xl)/2 ;
ea = abs((xu-xl)/xl);

test= fx(xl)*fx(xr);
if test < 0
xu=xr;
end
if test > 0
xl=xr;
end
if test == 0
ea=0;
end
if ea < es
break;
end

% Store calculated values in vectors


xl_all(i) = xl;
xu_all(i) = xu;
xr_all(i) = xr;
ea_all(i) = ea;
fxl_all(i) = fx(xl);
fxu_all(i) = fx(xu);
fxr_all(i) = fx(xr);
end

fprintf('\n Root= %f #Iterations = %d \n', xr,i);


fprintf(' How close is f(root) to zero? f(root)= %f \n', fx(xr));

% Display stored values


fprintf('\nStored Values:\n');
fprintf('xl_all: ');
disp(xl_all);
fprintf('xu_all: ');
disp(xu_all);
fprintf('xr_all: ');
disp(xr_all);
fprintf('ea_all: ');
disp(ea_all);
fprintf('fxl_all: ');
disp(fxl_all);
fprintf('fxu_all: ');
disp(fxu_all);
fprintf('fxr_all: ');
disp(fxr_all);
SORU 3
SORU 4
SORU 5

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy