Secant Method
clc;
clear;
% Shows the points obtained by the Secant Method when
% solving the equation func(x)=0. The two initial
% points are supplied, along with the number of
% required iterations.
func=@(x) 4*(x-2)^3+4*x-12;
current_1=0
current_2=10
iterations=5;
orbit=[current_1,current_2];
for i=1:iterations
disp('itter')
i
disp('slope')
disp('f(L)=')
feval(func,current_1)
disp('f(R)=')
feval(func,current_2)
disp('slope')
slope=(feval(func,current_2)-feval(func,current_1))/(current_2-current_1)
disp('new L')
current_1=current_2
disp('new R')
current_2=current_2-feval(func,current_2)/slope
orbit=[orbit,current_2];
end
orbit
clear;
% Shows the points obtained by the Secant Method when
% solving the equation func(x)=0. The two initial
% points are supplied, along with the number of
% required iterations.
func=@(x) 4*(x-2)^3+4*x-12;
current_1=0
current_2=10
iterations=5;
orbit=[current_1,current_2];
for i=1:iterations
disp('itter')
i
disp('slope')
disp('f(L)=')
feval(func,current_1)
disp('f(R)=')
feval(func,current_2)
disp('slope')
slope=(feval(func,current_2)-feval(func,current_1))/(current_2-current_1)
disp('new L')
current_1=current_2
disp('new R')
current_2=current_2-feval(func,current_2)/slope
orbit=[orbit,current_2];
end
orbit
0 Comments:
Post a Comment
<< Home