Using MATLAB or FreeMat
----------------------------
%%Matlab code for Bisection method
clear all
close all
%function for which root have to find
fun=@(x)
3.*cos(2.*x).*cos(4.*x)-2.*cos(6.*x).*cos(3.*x)-6.*cos(2.*x).*(sin(2.*x)).^2-5.*cos(3.*x)+5/2;
xx=linspace(0,1);
yy=fun(xx);
fprintf('for the function f(x)=')
disp(fun)
figure(1)
plot(xx,yy)
xlabel('x')
ylabel('f(x)')
title('x vs. f(x) plot')
[root]=bisection_method(fun,0,1,1000);
fprintf('\tRoot using Bisection method is %f.\n',root)
hold on
plot(root,fun(root),'r*')
grid on; box on;
%%table for x and f1(x)
fprintf('\n\t x\t\t\tf(x)\n')
xx=-5:1:5;
for i=1:length(xx)
rr=root+xx(i)*10^-10;
fprintf('\t%f+(%d*10^-10)=
%e\n',root,xx(i),fun(rr))
end
%function for which root have to find
fun=@(x)
3.*cos(2.*x).*cos(4.*x)-2.*cos(6.*x).*cos(3.*x)-6.*cos(2.*x).*(sin(2.*x)).^2-5.*cos(3.*x)+7/2;
xx=linspace(0,1);
yy=fun(xx);
fprintf('for the function f(x)=')
disp(fun)
figure(2)
plot(xx,yy)
xlabel('x')
ylabel('f(x)')
title('x vs. f(x) plot')
[root]=bisection_method(fun,0,1,1000);
fprintf('\tRoot using Bisection method is %f.\n',root)
hold on
plot(root,fun(root),'r*')
grid on; box on;
%%table for x and f1(x)
fprintf('\n\t x\t\t\tf(x)\n')
xx=-5:1:5;
for i=1:length(xx)
rr=root+xx(i)*10^-10;
fprintf('\t%f+(%d*10^-10)=
%e\n',root,xx(i),fun(rr))
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Matlab function for Bisection Method
function [root]=bisection_method(fun,x0,x1,maxit)
if fun(x0)<=0
t=x0;
x0=x1;
x1=t;
end
fprintf('\nRoot using Bisection method\n')
%f(x1) should be positive
%f(x0) should be negative
k=10; count=0;
while k>10^-10
count=count+1;
xx(count)=(x0+x1)/2;
mm=double(fun(xx(count)));
if mm>=0
x0=xx(count);
else
x1=xx(count);
end
err(count)=abs(fun(x1));
k=abs(fun(x1));
if count>=maxit
break
end
%
end
fprintf('\tAfter %d iteration root using Bisection method is
%f\n',count,xx(count))
root=xx(end);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Using MATLAB or FreeMat ---------------------------- Bisection Method and Accuracy of Rootfinding Consider the function f(0) =...
Problem 6 Implement a MATLAB function bisection.m of the form bisection (a, b, f, p, t) function [r, h] Beginning of interval [a, b] % b End of interval [a, b] % f function handle y = f(x, p) % p: parameters to pass through to f % t User-provided tolerance for interval width a: At each step j = 1 to n, carefully choose m as in bisection with the geometric (watch out for zeroes!) Replace a, b by...
Problem 6 Implement a MATLAB function bisection.m of the form bisection(a, b, f, p, t) function [r, h] % a Beginning of interval [a, bl % b: End of interval [a, b] % f: function handle y f(x, p) % p: parameters to pass through to f % t: User-provided tolerance for interval width At each step j 1 to n, carefully choose m as in bisection with the geometric (watch out for zeroes!) Replace [a, b] by the smallest...
Find the smallest positive root for the given function by using the bisection method with accuracy 10^-3 f(x) = 2x5 – x3
In MATLAB please Consider the nonlinear function: y = f(x) = x3 cos x a. Plot y as a function of x as x is varied between -67 and 67. In this plot mark all the locations of x where y = 0. Make sure to get all the roots in this range. You may need to zoom in to some areas of the plot. These locations are some of the roots of the above equation. b. Use the fzero...
Matlab method questions A zero of the function f(x) shown below is to be found. Use the image to answer Questions 15-17. 5 4 3 N f(x) 1 -2 4 6 8 10 N X What value will the Bisection Method converge to after many iterations using an initial lower guess XL = 0 and initial upper guess xu = 7? 0 1 2 3 4 O 5 6 O 7 8 O 이 9 O 10 There will be...
Using MATLAB and bisection Find the first 10 roots of the function y(x) = cos(5x). Note you will need to have a script file that steps along the x-axis and calls bisect when a root bracket is found.
please show answer in full with explanation, also show matlab 1. Consider the function f(x)2.753 +18r2 21 12 a) Plot the graph of f(x) in MATLAB and find all the roots of the function f(x) graphically. Provide the code and the plot you obtained. b) Compute by hand the first root of the function with the bisection method, on the interval -1; 0) for a stopping criterion of 1% c) How many iterations on the interval -1, 0 are needed...
Not in C++, only C code please In class, we have studied the bisection method for finding a root of an equation. Another method for finding a root, Newton's method, usually converges to a solution even faster than the bisection method, if it converges at all. Newton's method starts with an initial guess for a root, xo, and then generates successive approximate roots X1, X2, .... Xj, Xj+1, .... using the iterative formula: f(x;) X;+1 = x; - f'(x;) Where...
use C programing to solve the following exercise. Compute a root of the equation 4. (20 points) e-3 cos(x)-o using (a) Bisection Method between 0 and I. (b) Newton Method using an initial guess of I. Use e0.00001 Show that Newton Method has a faster convergence than Bisection Method Compute a root of the equation 4. (20 points) e-3 cos(x)-o using (a) Bisection Method between 0 and I. (b) Newton Method using an initial guess of I. Use e0.00001 Show...
Write a Matlab function for: 1. Root Finding: Calculate the root of the equation f(x)=x^3 −5x^2 +3x−7 Calculate the accuracy of the solution to 1 × 10−10. Find the number of iterations required to achieve this accuracy. Compute the root of the equation with the bisection method. Your program should output the following lines: • Bisection Method: Method converged to root X after Y iterations with a relative error of Z.