Hello
I am having trouble understanding how this loops would work.
Give the function (x*x*x*x) - (10*x*x*x) + (35*x*x) - (50*x) + 24
Write a program that will use bisection method to find the roots of this function.
Define lower limit and upper limit (e.g. -1.05 and 6.05)
Starting at the lower limit step along the X axis at intervals of 0.1 for H calculating the function values f(x) and f(x +h), then f(x+h) and f(x+2h) until the upper limit is exceeded. If sign of the function value changes this indicates a root between ranges. Apply bi sectional method to this range until root has been found with an epsilon of 0.000001, then continue on until upper limit has been exceeded and all 4 roots found. If the function is within 0.000001 of zero then root has been found therefore no need for bi sectional method.
Code:
#include "stdafx.h"
#include "math.h"
#define H 0.1
#define epsilon 0.000001
double F(double x);
int main(void)
{
double root, midpt, midvalue, rtvalue, rtpoint, ltvalue, ltpoint, a, b, c;
int loop_count;
printf("\nSet Lower and Upper Limit Ranges");
scanf_s("%lf %lf%", &a, &B)/>/>;
/*Interval Loop to find changes in sign*/
do {
c = a + H;
ltvalue = F(a);
rtvalue = F(B)/>/>;
if (ltvalue > 0 && rtvalue > 0 || ltvalue < 0 && rtvalue < 0);
a = H ++;
else
do {
midpt = (ltvalue + rtvalue)/2;
rtpoint = F(rtvalue);
midvalue = F(midpt);
loop_count ++;
if (rtvpoint * midvalue >= 0)
rtvalue = midpt;
else ltvalue = midpt;
}
while ((rtvalue - ltvalue) > epsilon);
root = (rtvalue+ltvalue)/2;
printf("\nRoot is: %.8f\n", root);
/*Continue on with intervals until next root indicator then apply bisectional method???*/
printf("\nNumber of Loops: %d\n", loop_count);
return 0;
}
/*Function of quartic equation*/
double F(double x){
return (x*x*x*x) - (10*x*x*x) + (35*x*x) - (50*x) + 24;
}
So we have a function and a range. Program requires to work along the X axis at 0.1 increments until it reaches a point where the value changes from positive to negative or negative to positive. Then apply bisection method within that range to a given accuracy then print that root. Then continue on X axis until the next change of sign is found. I am not sure how these loops are to be constructed.