Find areal root of equation cosx=3x-1 correct to 3 desimal places using iteration method.
answer:
#include<iostream.h>
#include<math.h>
#include<conio.h>
#define EPS 0.00005
#define F(X) (cos*x +1)/3
#define f(x) cos*x -3*x +1
void ITER();
void main()
{
cout << "\n\t Solution by ITERATION method \n" << endl;
cout <<"\n\t Eqution is:";
cout <<"\n\t\t\t\t cos*x +3*x +1=0\n\n";
ITER();
getch();
}
void ITER()
{
float x1,x2,x0,f0,f1,f2,error;
int i=0,n;
for(x1=1;;x1++)
{
f1=f(x1);
if(f1>0)
break;
}
for(x0=x1-1;;x0--)
{
f0=f(x0);
if(f0<0)
break;
}
x2=(x0=x1)/2;
cout <<"Enter the number of uterations:";
cin >>"%d",&n;
cout <<"\n\n\t\t The 1 approximation to the root is: %f",x2;
for(;i<n-1;i++)
{
f2=f(x2);
cout <<"\n\n\t\tThe %d approximation to the root is: %f",i+2,f2;
x2=f(x2);
error=fabs(f2-f1);
if(error<EPS)
break;
f1=f2;
}
if(error>EPS)
cout <<"\n\n\t NOTE:- The number of iterations are not sufficient.";
cout <<"\n\n\n\t\t---------------------------------";
cout <<"\n\t\t\t The root is %.4f",f2;
cout <<"\n\t\t\t----------------------------------";
}
When it was implemented on microsoft visual c++ Gave me four errors and one warning
error C2296: '*' : illegal, left operand has type 'double (__cdecl *)(double)' error C2296: '*' : illegal, left operand has type 'double (__cdecl *)(double)' error C2296: '*' : illegal, left operand has type 'double (__cdecl *)(double)' error C2296: '*' : illegal, left operand has type 'double (__cdecl *)(double)' warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
What do I do?
Thank you very much,

New Topic/Question
Reply




MultiQuote




|