I must do my work program to resolve these issues please help me where should I enter the following:

function :x^3+4x^2-10=0

interval a :
hnterval b :
tol(Permissible error):
The program gives the number of times the solutions and the general solution and when it is smaller than tol

pleas pleas

Recommended Answers

All 10 Replies

There simply isn't anything here useful to us. If you want any help, you're going to have to make an attempt yourself and explain things better, otherwise it's simply not possible to help due to lack of information.

You have to help us help you before we can do anything.

I hope this Mhaoti completions with me because I waited until I knew a lot of this note I am a newbie

#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
void main()
{
    float a
    cout<<"enter x^3:"<<endl;
    cin>>a;
    cout<<"enter x^2:"<<endl;
    cin>>b;
    cout<<"enter x:"<<endl;
    cin>>c;
    cout<<"enter valu:"<<endl;
    cin>>d;
    cout<<"enter interval 1:"<<endl;
    cin>>x;
    k=(a*pow(x,3)b*pow(x,2)c*xd);
    cout<<"enter interval 2:"<<endl;
    cin>>x1;
    k=(a*pow(x1,3)b*pow(x1,2)c*x1d);
    cout<<"enter Tol:"<<endl;
    cin>>g;
    t=2*g;
for (int i=1;i<t;i++)

Zorry dude, I'm quite new to this programming thing and have actually quite recently done a qudratic equation console program and I still have no idea what you are trying to do there.

Give us and explanation as to what this program is supposed to do and help will find you.

I hope this Mhaoti completions with me

I appreciate the fact that English is not your first language, but I have no idea what you are trying to say there.

So what are you trying to do with this function? Take the integral of it?

i am soory >>

i want solve this function by Bisection method

One of the methods of numerical analysis>>

Remember pasting in

marks is always going to get you further.

k=(a*pow(x,3)b*pow(x,2)c*xd);

Although not really knowing what you are supposed to do, I suspect the problem lies here within.

eg. c+xd does nothing.

The wikipedia page on that topic is great. There's an entire example in pseudocode (http://en.wikipedia.org/wiki/Bisection_method#Pseudo-code -- aside from minimal comments, it's all in function style names, so it should be understandable) and the diagram at the top is helpful. See how far you can get off of that.

#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
void main()
{
    float a,b,c,d,k,m,x,x1,t
    cout<<"enter x^3:"<<endl;
    cin>>a;
    cout<<"enter x^2:"<<endl;
    cin>>b;
    cout<<"enter x:"<<endl;
    cin>>c;
    cout<<"enter valu:"<<endl;
    cin>>d;
    k=(a*pow(x,3)b*pow(x,2)c*xd);
    cout<<k<<endl;
    cout<<"enter interval 1:"<<endl;
    cin>>x;
    cout<<"enter interval 2:"<<endl;
    cin>>x1;
    cout<<"enter Tol:"<<endl;
    cin>>t;
     do while (abs(x - x1) > 2*t)
   m = (x + x1) / 2
   If ((f(x1) * f(m)) < 0) Then
     x = m
   Else if ((f(x) * f(m)) < 0)
     x1 = m
   else 
     exit do
  end if

=========
ok > Is that right????

What missing

Yes, by magic the pseudocode will be translated into C++ by your pseudocode->C++ translator. :icon_rolleyes: The idea was to look at the pseudocode and get some ideas, not blindly copy and paste it in.

No one is going to do this for you. For your p-code to work, you'll need to separate your function out into a function named f (which takes a parameter x), and of course change the loop into actual C++.

Also, please use code tags when posting your code [code] //code goes here [/code]

#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
 
double f( double);
 
int main ( int argc, char *argv[])
{
int kmax;
double a,b,eps;
cout <<" Input a,b, eps, kmax\n ";
cin>> a >> b >> eps >> kmax;//use big kmax , eps 0.5e-6
cout << " The input data are\n";
cout << "a= "<< a << "b= "<< b;
cout << "eps= "<< eps << "kmax= "<< kmax<< endl;
cout<< " The results are\n";
cout<< "k a b x f(x)\n";
 
int k=1;
 
double x=0.5*(a+b );//first bisection
 
while (( k<=kmax) || (fabs(b-a)>eps)) // <-- this has changed
{
cout << setw(2)<< k << setprecision(5)<< fixed<< setw(8)<< a<< setw(8)<< b << setprecision(6) <<setw(10)<<x<< setw(12)<<f(x) << endl;
if (f(x) <0)
a=x;
else
b=x;
x= 0.5*(a+b);
 
k++;
}
if ( (k>kmax) || ( fabs(b-a)) < eps  )
cout << "no convergence";
else
cout << " \nThe root = "<< x<< endl;
 
return 0;
}
double f(double x){
return (1*pow(x,3)-7*pow(x,2)+14*x-6);
}

Ok Stales Do not be nervous Haha

This code, but I want to stop the program when Alabslon entered

Then when I want to write not what the word synonymous with

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.