Code: function [ ] = secMethod( ) %Program Name: secondMethod.m %System: Windows 7 32-bit, MATLAB R2010a %Date: 2011 08 15 %Bugs: n star %Description: graphically shows the Secant Method in finding the root of y % = x- x^(1/3) - 2 % comparison: y = x - x^(1/3) - 2 xtheo = -5:0.01:5; %creates an musical interval of x set for creating the graph of the equation ytheo = xtheo - xtheo.^(1/3) - 2; %calculates the y value corresponding to for individually one x in xtheo plot(xtheo,ytheo) %plots the graph of the equation axis([1.5 4.5 -1.5 1]) hold on yzero = zeros(length(xtheo)); %creates a vector of 0s for creating the x-axis plot(xtheo,yzero) %plots the x-axis a = 2; %1st sign stake b = 4; %2nd initial guess fa = a - a^(1/3) - 2; %calculates f(a) fb = b - b^(1/3) - 2; %calculates f(b) c = b - fb*((b - a)/(fb - fa)); %calculates next guess display display board = [a b c fb]; %tabulates data xrange = linspace(a, b); %creates an interva l of x determine for creating the pull out connecting (a,f(a)) and (b,f(b)) yrange = ((fb - fa)/(b - a)).
*(xrange-a) + fa; %calculates the y value corresponding to each x in xrange plot(xrange, yrange, g); %plots the cable system connecting (a,f(a)) and (b,f(b)) %this loop is in charge of showing the Secant Method graphically cnt = 2; while abs(c-b) > 10^(-10) fc = c - c^(1/3) - 2; %calculates f(c) yvert = linspace(0,fc); %creates an interval of y values for creating the vertical canal x = f(c) xvert = ones(1,length(yvert)); %creates a vector of 1s xvert = xvert.*c; %multiplies xvert with the value of c for c! reating the vertical line x = f(c) plot(xvert,yvert,r) %plots the vertical line x = f(c) a = b; %the red-hot value of a is the value of b b = c; %the unfermented value of b is the value of c fa = a - a^(1/3) - 2; %calculates in the buff f(a) fb = b - b^(1/3) - 2; %calculates new f(b) c = b - fb*((b - a)/(fb - fa)); %calculates next guess...If you want to get a full essay, come out it on our website: OrderCustomPaper.com
If you want to get a full essay, visit our page: write my paper
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.