Secant Method - Matlab Script
These are some of my university matlab assignments.
This is a discription and explanation of the secant methid uses matlab to show the step by step iteration that are done to calculate the end value.
Using the following script, it produces a straight forward answer as to what the answer is by using the secant methid.
function x = secant(f_str, x0, x1, n)
% SECANTÂ Secant method
% X = SECANT(F_STR, X0, X1, N) performs N iterations of the secant method
% on the function f, starting with the initial iterates X0 and X1, where
% F_STR is the string representation of f.
f = inline(f_str);
xp = x0;
fp = f(xp);
x = x1;
fx = f(x);
for i = 1:n
   xn = x - fx * (x - xp) / (fx - fp)
   xp = x;
   fp = fx;
   x = xn;
   fx = f(x);
end
However if you would like to see the step by step done behind the scenes of the secant method, use the following script.
function x = secant(f_str, x0, x1, n)
% SECANT Secant method
% X = SECANT(F_STR, X0, X1, N) performs N iterations of the secant method
% on the function f, starting with the initial iterates X0 and X1, where
% F_STR is the string representation of f.
% in the form f(x) = 0
f = inline(f_str);
a = x0;
b = x1;
disp('Number of Iterations =')
disp(0)
disp('Xn =')
disp(a)
disp('f(Xn) =')
disp(f(a))
disp('Number of Iterations =')
disp(1)
disp('Xn =')
disp(b)
disp('f(Xn) =')
disp(f(b))
  Â
for i = (1:n-1)
   x = b - (f(b) * ((b-a)/(f(b)-f(a))));
   if b == x
       disp('This is the Highest Accuracy Achievable')
       i = i-1;
       break
   end
   a = b;
   b = x;
  Â
   disp('Number of Iterations =')
   disp(i+1)
   disp('Xn =')
   disp(x)
   disp('f(Xn) =')
   disp(f(x))
end
disp('Number of Iterations Done:')
disp(i+1)
end
The secant method is based off Newtons method which uses the differential of the function to closly approximate the answer, where by the more iterations, the closer the answer becomes. In stead of the differential, uses a tangent or secant line to approximate it. The accuraccy of answer increases by a factor of 1.618, meaning each iteration increases the decimal place accuracy by 1.618 places each time.
Other Iterative and Mathematical Method using Matlab and also other Mathematical Examples:
>>> Romberg Numerical Integration - Matlab Script
>>> Simpson's Rule and Trapezoidal Rule of Numerical Integration - Matlab Scripts
>>>Â Newtons Method of finding Roots - Matlab Script
>>>Â Bisection Method of finding Roots - Matlab Script
>>> Lagrange Method and Newton Divided Difference Method - Matlab Scripts
Other Articles I have writen include:
-
Newton Method and Bisection Method - Matlab Scripts
| By djmcv90 | in College and University
Here are some iteration methods ive used at uni...
-
How to derive Miley Cyrus using Iterative Mathematics & Hilary Duff
| By djmcv90 | in Humor and Comedy
a comic spoof of Miley Cyrus and some Hilary Duff, includes how to derive them using iterative methods...
-
What is Plagiarism? | By faris_jayz | in College and University
Plagiarism is when writers intentionally or unintentionally present another person's words, ideas, or work as their...
-
Planning your College Courses | By koopalo | in College and University
Knowing what college courses you're going to take ahead of time saves you a lot of time, stress, and sometimes even...
-
How to Choose a College Major | By koopalo | in College and University
Do you feel pressured to choose a college major and don't know how to decide? Deciding on the right one for you can...
-
Exaggerated Claims of Executive Privilege; Archibald Cox – A Man of Uncompromising Integrity | By marie.thomas | in College and University
Just one day after President Nixon refused to comply with a federal appeals court order to surrender the hostage â€...
-
Guide to buying your textbooks cheap. | By luvikavi | in College and University
Buying textbooks for college courses is probably one of the most daunting aspects of our college career. Read this ...
-
Simpson's Rule and Trapezoidal Rule of Numerical Integration - Matlab Scripts | By djmcv90 | in College and University
Simpson's Rule and Trapezoidal Rule of Numerical Integration calculates the area under a function by breaking the f...
-
Romberg Numerical Integration - Matlab Script | By djmcv90 | in College and University
Romberg numerical integration uses trapenzoidal intergration to increase the accuracy of calculating an area. It bu...
-
Save money with computers - Build your own (Part 3) | By djmcv90 | in Computers
part 3 of how to build a computer and save money doing it...
-
How to Build your Own Computer Cheap - Save Money | By djmcv90 | in Computers
some tips and ways to build a computer...
-
Increased Obesity Leads to Worlds Largest Joke - Mind the Pun | By djmcv90 | in Humor and Comedy
Fat people are everywhere overconsuming and not letting any starving africans get any food, so to solve the problem...








No comments yet.