CS计算机代考程序代写 matlab [Content_Types].xml

[Content_Types].xml

_rels/.rels

matlab/document.xml

matlab/output.xml

metadata/coreProperties.xml

metadata/mwcoreProperties.xml

metadata/mwcorePropertiesExtension.xml

metadata/mwcorePropertiesReleaseInfo.xml

Bracketing Methods: Bisection Method In this livescript, you will learn how to Write a MATLAB program that implements the Bisection method to solve an algebraic nonlinear equation We’ll be considering the problem f(x)=x^{3}-x=0 Equation 1. It is always a good idea to plot f(x) to see what it looks like and get an idea where the roots are. (a) Plot f(x) for -2\leq x \leq 2 x=linspace(-2,2,100);
fx=x.^3-x;
plot(x,fx);
xlabel(‘x’);
ylabel(‘f(x)’);

%Plot a horizontal line at y=0 so that we can better see where the root is
y=0;
line([-2,2],[y,y]) From the graph generated, you can see that there is one root at -1 , one at x=0 and another one at x=1 . (b) To get an idea of how the bisection method works run the function \texttt{bisection\_example} . You’re going to have to choose lower and upper bounds for the root and then choose whether to move the upper or lower bound to the average value. You don’t have to understand how this function works, as the function is written so that you can interact with it and choose whether x_{\ell}=x_{r} or x_{u}=x_{r} at each step. bisection_example Cutting out all the unnecessary code for interactivity, the Bisection method can be implemented using %%%%%%%%%%%%%%%%%%%%%%%%%%%
% bisection_method_solver %
%%%%%%%%%%%%%%%%%%%%%%%%%%%

f=@(x) x.^3-x;

x_l = -2.2; %Initial lower guess of root
x_u = -0.8; %Initial upper guess of root

eps = 1.0e-6; %Accuracy of your answer
maxiter = 50; %maximum number of iterations

x_r=(x_l+x_u)/2

while abs(f(x_r))>eps
f_l=f(x_l);
f_u=f(x_u);
f_r=f(x_r);
if f_r*f_l < 0 x_u= x_r; elseif f_r*f_u < 0 x_l= x_r; end x_r=(x_l+x_u)/2 end (c) Change the values of \texttt{x\_l} and \texttt{x\_u} and see if you can make the Bisection method find the different roots of the equation. Try \texttt{x\_l}=-1.2 and \texttt{x\_u}=1.2 \texttt{x\_l}=-1.2 and \texttt{x\_u}=1.3 \texttt{x\_l}=-1.2 and \texttt{x\_u}=1.1 What do the values converge to? Can think of why this might be the case? manual code ready 0.4 true false x=linspace(-2,2,100); 0 11 11 false false fx=x.^3-x; 1 12 12 false false plot(x,fx); 2 13 13 false false xlabel('x'); 3 14 14 false false ylabel('f(x)'); 4 15 15 false false y=0; 5 18 18 false true line([-2,2],[y,y]) 6 19 19 true true bisection_example 7 25 25 true false f=@(x) x.^3-x; 8 32 32 false false x_l = -2.2; %Initial lower guess of root 9 34 34 false false x_u = -0.8; %Initial upper guess of root 10 35 35 false false eps = 1.0e-6; %Accuracy of your answer 11 38 38 false false maxiter = 50; %maximum number of iterations 12 39 39 false false x_r=(x_l+x_u)/2 13 41 41 false true while abs(f(x_r))>eps
f_l=f(x_l);
f_u=f(x_u);
f_r=f(x_r);
if f_r*f_l < 0 x_u= x_r; elseif f_r*f_u < 0 x_l= x_r; end x_r=(x_l+x_u)/2 end 14 43 53 2020-03-08T05:24:12Z 2020-08-09T06:25:20Z application/vnd.mathworks.matlab.code MATLAB Code R2020a 9.8.0.1298242 254b40cb-f9a8-4231-9f83-4e5878de3db6 9.8.0.1417392 R2020a Update 4 Jun 24 2020 1882048