Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here is a java program for Muller's method, how can I use it to find the complex roots? The complex roots is 0.34532 +/- 1.31873i

Here is a java program for Muller's method, how can I use it to find the complex roots?

The complex roots is 0.34532 +/- 1.31873i

// Program

import java.io.*; import static java.lang.Math.*; public class Muller { static final int MAX_ITERATIONS = 10000; // function to calculate f(x) static double f(double x) { // Taking f(x) = x ^ 3 + 2x ^ 2 + 10x - 20 return x*x*x-2.0*x*x-5; } static void Muller(double a, double b, double c) { int i; double res; for (i = 0;; ++i) { // Calculating various constants required // to calculate x3 double f1 = f(a); double f2 = f(b); double f3 = f(c); double d1 = f1 - f3; double d2 = f2 - f3; double h1 = a - c; double h2 = b - c; double a0 = f3; double a1 = (((d2*pow(h1, 2)) - (d1*pow(h2, 2))) / ((h1*h2) * (h1-h2))); double a2 = (((d1*h2) - (d2*h1))/((h1*h2) * (h1-h2))); double x = ((-2*a0)/(a1 + abs(sqrt(a1*a1-4*a0*a2)))); double y = ((-2*a0)/(a1-abs(sqrt(a1*a1-4*a0*a2)))); // Taking the root which is closer to x2 if (x >= y) res = x + c; else res = y + c; // checking for resemblance of x3 with x2 till // two decimal places if (Math.abs(res-c)<0.0001) break; a = b; b = c; c = res; System.out.println("Iteration "+(i+1)+" root is "+c); if (i > MAX_ITERATIONS) { System.out.println("Root cannot be found using" + " Muller's method"); break; } } if (i <= MAX_ITERATIONS) System.out.println("The value of the root is " + res); } // Driver main function public static void main(String args[]) { double a = 3, b = 4, c = 5; Muller(a, b, c); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Medical Image Databases

Authors: Stephen T.C. Wong

1st Edition

1461375398, 978-1461375395

More Books

Students also viewed these Databases questions