The Bisection Method


Finding the roots of a different function



Download 263,5 Kb.
bet5/5
Sana26.04.2022
Hajmi263,5 Kb.
#583455
1   2   3   4   5
Bog'liq
fdocuments.in the-bisection-method

Finding the roots of a different function

  • Suppose we want to find the root of
  • in the interval [0..4]
  • f(x) = x3 + x - 3

Finding the roots of a different function (cont.)

  • Changes to the Java program:
  • // Solves: x^3 + x - 3 = 0
  • public class Bisection02
  • {
  • public static void main(String[] args)
  • {
  • final double epsilon = 0.00001;
  • double a, b, m, y_m, y_a;
  • a = 0; b = 4;
  • while ( (b-a) > epsilon )
  • {
  • m = (a+b)/2; // Mid point

Finding the roots of a different function (cont.)

  • y_m = m*m*m + m - 3.0; // y_m = f(m)
  • y_a = a*a*a + a - 3.0; // y_a = f(a)
  • if ( (y_m > 0 && y_a < 0) || (y_m < 0 && y_a > 0) )
  • { // f(a) and f(m) have different signs: move b
  • b = m;
  • }
  • else
  • { // f(a) and f(m) have same signs: move a
  • a = m;
  • }
  • System.out.println("New interval: [" + a + " .. " + b + "]");
  • }
  • System.out.println("Approximate solution = " + (a+b)/2 );
  • }
  • }

Finding the roots of a different function (cont.)

  • Example Program: (Demo above code)
    • Prog file: http://mathcs.emory.edu/~cheung/Courses/170/Syllabus/07/Progs/Bisection02.java
  • How to run the program:
  • Right click on link and save in a scratch directory
  • To compile: javac Bisection02.java
  • To run: java Bisection02

Finding the roots of a different function (cont.)

  • We had to change the body of the Java program to find the root of a different function
  • This is very inconvenient
  • It would be more convenient to if we can write:
  • y_m = f(m);
  • y_a = f(a);

Finding the roots of a different function (cont.)

  • When we solve a different function, we make changes to the function definition f()
  • This is indeed possible in Java...
  • However, we have not study user-defined methods yet.
  • But we will get there very soon.

Download 263,5 Kb.

Do'stlaringiz bilan baham:
1   2   3   4   5




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish