Code: function [ ] = secMethod( ) %Program Name: secondMethod.m %System: Windows 7 32-bit, MATLAB R2010a %Date: 2011 08 15 %Bugs: n oneness %Description: graphically shows the Secant Method in finding the root of y % = x- x^(1/3) - 2 % comparability: y = x - x^(1/3) - 2 xtheo = -5:0.01:5; %creates an detachment of x set for creating the graph of the equation ytheo = xtheo - xtheo.^(1/3) - 2; %calculates the y value corresponding to for apiece 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 consider 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 add-in = [a b c fb]; %tabulates data xrange = linspace(a, b); %creates an interval of x s et 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 military control x = f(c) xvert = ones(1,length(yvert)); %creates a vector of 1s xvert = xvert.*c; %mu ltiplies xvert with the value of c for creat! ing 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 hot value of b is the value of c fa = a - a^(1/3) - 2; %calculates new(a) 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, ordination 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