Question

Direct Search Method – Write a C code to find all the roots of equation between...

Direct Search Method

– Write a C code to find all the roots of equation between 1 and 10 by using direct search method with

Deltax= 0. 01: 49.55x− 12.8x^2+x^3=59.5

0 0
Add a comment Improve this question Transcribed image text
Answer #1

A simple method could be created to achieve the same functionality in code.

#include <stdio.h>
#include <math.h>
#define PI 3.14159265

double f(double x);
double direct(double a, double b, int n);

int main()
{
       double x0 = 1, xn = 10;
       // Considering number of steps 1000
       int n = 1000;

       printf( "The root is %f\n", direct(x0, xn, n) );

       return 0;
}

double f(double x)
{
       double y;
       y = 49.55*x - 12.8*x*x + x*x*x - 59.5;
       return y;
}

// Method to search root via direct method
double direct(double a, double b, int n)
{
       int i;
       double dx, x, f1, f2;
       dx = 0.01;
       f1 = f(a);
       for (i = 1; i <= n; i++) {
           x = a + dx * i;
           f2 = f(x);
           if (f1 * f2 <= 0) break;
           f1 = f2;
       }
       return x - dx/2;
}

Happy Coding!

Add a comment
Know the answer?
Add Answer to:
Direct Search Method – Write a C code to find all the roots of equation between...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT