473,386 Members | 1,754 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

how to write a c program to find the roots of the equation using bisection method

6
to write a c program to find the roots of the equation using bisection method
that too using array or pointers
Aug 29 '06 #1
8 22505
D_C
293 100+
1. You posted a similar thread to this, please refrain from doing that.
2. For which equation are we finding roots? What is the bijection method? A bijection is a 1-1 onto function, so "1-1 onto function method" really doesn't help. You should be more specific, then we might be able to help you.
Aug 29 '06 #2
Niheel
2,460 Expert Mod 2GB
Thanks for the headsup D_C.
Dup has been deleted.
Aug 29 '06 #3
aruna
6
i just wrote a c program to find the roots of equation using bisection method
but there is some error prevails .i think my logic is correct please help out
this my program



Expand|Select|Wrap|Line Numbers
  1. /* to find the roots using bisection method*/
  2. # include <stdio.h>
  3. # include <conio.h>
  4. # include<stdlib.h>
  5. # include <math.h>
  6. # define EPS .00001
  7. double F(double x);
  8. double root(double fVal1,double fVal2);
  9.  
  10. void main()
  11. {
  12.  
  13.  
  14.     double fVal1,fVal2;
  15.     clrscr();
  16.     printf("enter the values ");
  17.     scanf("%f %f",&fVal1,&fVal2);
  18.     printf("the roots of the euation is %1.9f\n",root(fVal1,fVal2));
  19.     getch();
  20. }
  21.     double root(double fVal1,double fVal2)
  22.     {
  23.         int nCtr=0;
  24.         double fTest1,fTest2,fTest3,fVal,fNum;
  25.  
  26.         fTest1=F(fVal1);
  27.         fTest2=F(fVal2);
  28.         if((fTest1*fTest2)>0)
  29.         {
  30.             printf("both are of equal sign");
  31.             exit(0);
  32.         }
  33.         else
  34.  
  35.         {
  36.             do
  37.             {
  38.                 nCtr++;
  39.                 fVal1=(fVal1+fVal2)/2;
  40.                 fTest3=F(fVal);
  41.             if(fTest1*fTest3>0)
  42.  
  43.             {
  44.                 fTest1=fTest3;
  45.                 fVal1=fVal;
  46.             }
  47.             else
  48.             {
  49.                  fTest2=fTest3;
  50.                  fVal2=fVal;
  51.  
  52.             }
  53.             fNum=fabs (fVal2-fVal1);
  54.  
  55.  
  56.             } while(fNum>EPS);
  57.         }
  58.             return fabs(fVal2)>fabs(fVal1)?fVal2:fVal1;
  59.  
  60.  
  61.  
  62.  
  63.  
  64.            }
  65.            double F(double x)
  66.            {
  67.             return (x*x*x)+(3*x)-5;
  68.  
  69.            }
  70.  
Sep 3 '06 #4
Banfa
9,065 Expert Mod 8TB
Firstly, as has already been stated, please do not start multiple threads about the same problem, post to your original thread. I have now merged the 2 relevent threads.

As to your code.

strangely I had to change

double fVal1,fVal2;

in main to

float fVal1,fVal2;

in order to get the correct values into the program.

A more serious error is that in

double root(double fVal1,double fVal2)
{
...
}

you declare and use a value fVal but you never initialise it to anything.
Sep 3 '06 #5
aruna
6
i have changed my program still iam not getting it
# include <stdio.h>
# include <conio.h>
# include<stdlib.h>
# include <math.h>
# define EPS .00001
float F(float x);
float root(float fVal1,float fVal2);

void main()
{


float fVal1,fVal2,;
clrscr();
printf("enter the values ");
scanf("%f %f",&fVal1,&fVal2);
printf("the roots of the euation is %1.9f\n",root(fVal1,fVal2));
getch();
}
float root(float fVal1,float fVal2)
{
int nCtr=0;
float fTest1,fTest2,fTest3,fVal,fNum;

fTest1=F(fVal1);
fTest2=F(fVal2);
if((fTest1*fTest2)>0)
{
printf("both are of equal sign");
exit(0);
}
else

{
do
{
nCtr++;
fVal=(fVal1+fVal2)/2;
fTest3=F(fVal);
if(fTest1*fTest3>0)

{
fTest1=fTest3;
fVal1=fVal;
}
else
{
fTest2=fTest3;
fVal2=fVal;

}
fNum=fabs (fVal2-fVal1);


} while(fNum>EPS);
}
return fabs(fVal2)>fabs(fVal1)?fVal2:fVal1;





}
float (float x)
{
return (x*x)-5;

}
Sep 4 '06 #6
aruna
6
i have just wrote a program to find the roots of the equation using bisection method
but there is some mistake iam not getting the output.comment iam getting as abnormal termination.so please help me
here is my program.


Expand|Select|Wrap|Line Numbers
  1. /* to find the roots using bisection method*/
  2. # include <stdio.h>
  3. # include <conio.h>
  4. # include<stdlib.h>
  5. # include <math.h>
  6. # define EPS .00001
  7. float F(float x);
  8. float root(float fVal1,float fVal2);
  9.  
  10. void main()
  11. {
  12.  
  13.  
  14.     float fVal1,fVal2,;
  15.     clrscr();
  16.     printf("enter the values ");
  17.     scanf("%f %f",&fVal1,&fVal2);
  18.     printf("the roots of the euation is %1.9f\n",root(fVal1,fVal2));
  19.     getch();
  20. }
  21.     float root(float fVal1,float fVal2)
  22.     {
  23.         int nCtr=0;
  24.         float fTest1,fTest2,fTest3,fVal,fNum;
  25.  
  26.         fTest1=F(fVal1);
  27.         fTest2=F(fVal2);
  28.         if((fTest1*fTest2)>0)
  29.         {
  30.             printf("both are of equal sign");
  31.             exit(0);
  32.         }
  33.         else
  34.  
  35.         {
  36.             do
  37.             {
  38.                 nCtr++;
  39.                 fVal=(fVal1+fVal2)/2;
  40.                 fTest3=F(fVal);
  41.                 if(fTest1*fTest3>0)
  42.  
  43.                 {
  44.                     fTest1=fTest3;
  45.                     fVal1=fVal;
  46.                 }
  47.                 else
  48.                 {
  49.                      fTest2=fTest3;
  50.                      fVal2=fVal;
  51.  
  52.                 }
  53.                 fNum=fabs (fVal2-fVal1);
  54.  
  55.  
  56.             } while(fNum>EPS);
  57.         }
  58.         return fabs(fVal2)>fabs(fVal1)?fVal2:fVal1;
  59.  
  60.  
  61.  
  62.  
  63.  
  64.            }
  65.            float (float x)
  66.            {
  67.             return (x*x)-5;
  68.  
  69.            }
  70.  
Sep 7 '06 #7
Banfa
9,065 Expert Mod 8TB
Please do NOT create multiple threads about the same problem

Please DO you the [code] and [/code] to delimit you code.

The posted code does not compile, please post compiling code. I would suggest that rather than typeing your code into the message box you copy and paste it from the source file once you have got the code compiling so we are all working from the same base line.
Sep 7 '06 #8
[


/*The Bisection Method to solve x*x*x+3*x-5***********/
#include<stdio.h>
#include<conio.h>
#include<math.h>

float f(float x);
main()
{

float a,b,y,r1,r2,r3;
do{
printf("\nenter approximate interval");
scanf("%f%f",&a,&b);
r1=f(a);
r2=f(b);
}while(r1*r2>0);
printf("a\t\tb x=(a+b)/2 f(x)\n\n");
do{
r1=f(a);
r2=f(b);
y= (a+b)/2.0;
r3=f(y);
printf( "%.4f %.4f %.4f %.4f",a,b,y,r3);
if(r1*r3<0)
b=y;
else
a=y;
printf("\n");
}while(fabs(r3)>0.0001);
printf("\n The approx sol is %.4f",y);
getch();
return 0;
}

float f(float x )
{
float f1;
f1=(x*x*x)+(3*x)-5;
return(f1);
}

well i hope it will help you.
its simple but it works!!.
Oct 5 '06 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Stud Muffin | last post by:
Hey Basically, I'm trying to take objects created in microsoft word using equation editor (for creating clean looking math/physics equations) and putting them into some sort of webpage format....
5
by: Justin Caldicott | last post by:
Hi There are n solutions to the nth root of any number, eg: (-8)^(1/3) = 1 + sqrt(3)i or -2 or 1 - sqrt(3)i The following code:
1
by: Dumidu | last post by:
Help me to write a programme to solve mannings equation using Newton-Raphson method. Newton-Raphoson metod= X^(m+1)= X^m - f(x^m)/ mannings equation = V= (1/n)*r^(2/3)*s^(1/2)
18
by: anand | last post by:
*********************************************************************************************************** #include<stdio.h> #include<conio.h> #include<math.h> void main() { double...
1
by: salman patni | last post by:
hi myself patni salman i am studied in amit collage aurangabad.i need solution of bisection method program using c language with algorithm
5
by: CoreyWhite | last post by:
It is possible to use martingale probability theory to beat some games of chance. In a fair game of coin toss, where the odds reach an equilibrium of 50/50 chain reactions do occur. This can be...
3
by: hazelfogbeam | last post by:
guys i tried constructing a programe and did but the problem when i run it the screen disappears and no output is presented. I am posting in the question as well as the script which i wrote,please...
2
by: Baba sina | last post by:
How can I solve f(x) with bisection method with the interval ?
3
by: newbprogrammer | last post by:
I just started programming in c++ and i tried to explore and do programs on my own... So i wanted to do a program that would help me in my daily school work ... a program to solve quadratic...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.