Newton Method and Bisection Method - Matlab Scripts
Here are some iteration methods ive used at uni
For more information about the inputs see the other matlab script on the secant method.
Here are 2 scripts on Newtons method and the Bisection method.
Newtons methods is based on using the derivative at a point to help calculate a closer value and this continues to find a closer and closer value.
The bisection method, as the name suggests, halves the distance between 2 points continuously until the point in between is accurate enough.
The bisection method is quite slow compared to newtons method as it only halves the distance, yet newtons method uses the gradient to approximate quickly with fewer iterations.
Newtons Method
function x = newton_method(f_str,df_str,x0,n)
% in the form f(x) = 0
f = inline(f_str);
df = inline(df_str);
disp('Number of Iterations =')
disp(0)
x = x0;
xn = 0;
disp('Xn =')
disp(x)
disp('f(x) =')
disp(f(x))
disp('f''(x) =')
disp(df(x))
for i = 1:n
   xn = x - (f(x)/df(x));
   if x == xn
       disp('This is the Highest Accuracy Achievable')
       i = i-1;
       break
   end
   x = xn;
disp('Number of Iterations =')
disp(i)
disp('Xn =')
disp(x)
disp('f(x) =')
disp(f(x))
disp('f''(x) =')
disp(df(x))
end
disp('Number of Iterations Done:')
disp(i)
end
Bisection Method
function x = bisection(f_str,x0,x1,n)
% in the form f(x) = 0
f = inline(f_str);
a = x0;
b = x1;
disp('Number of Iterations =')
disp(0)
disp('a =')
disp(a)
disp('b =')
disp(b)
x = (a+b)/2;
disp('x =')
disp(x)
disp('f(a)=')
disp(f(a))
disp('f(b)=')
disp(f(b))
disp('f(x)=')
disp(f(x))
for i = 1:(n)
   if (f(x) > 0 && f(b) > 0) || (f(x) < 0 && f(b) < 0)
       b = x;
   elseif (f(x) > 0 && f(a) > 0) || (f(x) < 0 && f(a) < 0)
       a = x;
   else disp('This is the Highest Accuracy Achievable')
       i = i-1;
       break
   end
   disp('Number of Iterations =')
   disp(i)
       disp('a =')
       disp(a)
       disp('b =')
       disp(b)
  Â
   x = (a+b)/2;
   disp('x =')
   disp(x)
   disp('f(a)=')
   disp(f(a))
   disp('f(b)=')
   disp(f(b))
   disp('f(x)=')
   disp(f(x))
end
disp('Number of Iterations Done:')
disp(i)
end
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
>>>Â Secant Method of finding Roots - Matlab Script
>>> Lagrange Method and Newton Divided Difference Method - Matlab Scripts
Other Articles I have writen include:
-
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...
-
Secant Method - Matlab Script
| By djmcv90 | in College and University
These are some of my university matlab assignments....
-
Generate and Animate Electric Sheep Flame Fractals Quickly - Free Screensavers
| By djmcv90 | in Computers
How to create awesome screensavers from your own computer using fractal generation....
-
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.