473,809 Members | 2,742 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

6 New Member
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 22540
D_C
293 Contributor
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,456 Recognized Expert Moderator Top Contributor
Thanks for the headsup D_C.
Dup has been deleted.
Aug 29 '06 #3
aruna
6 New Member
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 Recognized Expert Moderator Expert
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 New Member
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,&fVa l2);
printf("the roots of the euation is %1.9f\n",root(f Val1,fVal2));
getch();
}
float root(float fVal1,float fVal2)
{
int nCtr=0;
float fTest1,fTest2,f Test3,fVal,fNum ;

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

{
do
{
nCtr++;
fVal=(fVal1+fVa l2)/2;
fTest3=F(fVal);
if(fTest1*fTest 3>0)

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

}
fNum=fabs (fVal2-fVal1);


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





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

}
Sep 4 '06 #6
aruna
6 New Member
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 Recognized Expert Moderator Expert
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
priya mahajan
9 New Member
[


/*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
8934
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. But they come out grossly unalligned and ugly when I try to directly copy and paste into microsoft frontpage 2000. Few things I could do is place them directly using x/y coord (which i don't know how to do), or just taking screenshots and use...
5
3216
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
2876
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
2077
by: anand | last post by:
*********************************************************************************************************** #include<stdio.h> #include<conio.h> #include<math.h> void main() { double a,b,c,fa,fb,fc,err; int count;
1
4364
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
2242
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 explained using martingale probability theory, but in simpler terms it only shows an example of how order emerges out of chaos. Example: One player has 3 pennies, and another player has only 1 penny. A fair coin is tossed every round to determine...
3
1393
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 send a reply to me abt it. question is: using if statement,to print the roots of a quadratic equation,given the condition as follows: IF ROOTS b*b-4*a*c>0 ...
2
3188
by: Baba sina | last post by:
How can I solve f(x) with bisection method with the interval ?
3
1988
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 equations.. I wrote the code correctly but errors are still detected and i have no idea why.. almost gave up and banged my head on the wall .. so i would really appreciate help.. This is the code so far.. #include <cmath> #include <iostream> using...
0
9721
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10637
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10379
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10115
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7660
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3014
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.