conm file
conm file
#include<stdio.h>
#include<math.h>
float fun (float x)
{
return (x*x*x - 4*x - 9);
}
void bisection (float *x, float a, float b, int *itr)
/* this function performs and prints the result of one iteration */
{
*x=(a+b)/2;
++(*itr);
printf("Iteration no. %3d X = %7.5f\n", *itr, *x);
}
Int main ()
{
int itr = 0, maxmitr;
float x, a, b, allerr, x1;
printf(“This code is written by Amisha \n”);
printf("\n Enter the values of a, b, allowed error and maximum iterations:\n");
scanf("%f %f %f %d", &a, &b, &allerr, &maxmitr);
bisection (&x, a, b, &itr);
do
{
if (fun(a)*fun(x) < 0)
b=x;
else
a=x;
bisection (&x1, a, b, &itr);
if (fabs(x1-x) < allerr)
{
printf("After %d iterations, root = %6.4f\n", itr, x1);
return 0;
}
x=x1;
}
while (itr < maxmitr);
printf("The solution does not converge or iterations are not sufficient");
return 1;
}
This code is written by Amisha
Enter the values of a, b, allowed error and maximum iterations:
3
2
0.004
20
Iteration no. 1 X = 2.50000
Iteration no. 2 X = 2.75000
Iteration no. 3 X = 2.62500
Iteration no. 4 X = 2.68750
Iteration no. 5 X = 2.71875
Iteration no. 6 X = 2.70312
Iteration no. 7 X = 2.71094
Iteration no. 8 X = 2.70703
After 8 iterations, root = 2.7070
if(f2<0)
{
t=fabs(f2);
}
else
{
t=f2;
}
}
while(t>ESP);
printf("\n______________________________________________\n");
printf("\n\nApp.root = %f",x3);
getch();
}
________________________________________
x1 x2 x3 f(x1) f(x2)
______________________________________________
printf("\n");
for(i=0;i<m;i++){
printf("\t%f",q[i]);
}
printf("\t%f",q[m]);
return(q[m]);
}
void main(){
int m,i,flag=0;
float r, x,x1, fx, fdx;
printf("BIRGE-VIETA METHOD\n");
printf("This is written by Amisha\n");
printf("\nEnter the highest degree of the equation (max 5): ");
scanf("%d",&m);
for(i=0;i<=m;i++){
printf("\n Coefficient x[%d] = ",m-i);
scanf("%f",&p[i]);
ply[i] = p[i];
}
printf("\nEnter the initial value x0 : ");
scanf("%f",&r);
x = r;
do{
printf("\n%f\n",x);
fx = synth(m,x);
for(i=0;i<=m;i++){
p[i]=q[i];
}
fdx = synth(m-1,x);
x1 = x - (fx/fdx);
for(i=0;i<=5;i++){
p[i]=ply[i];
}
}while(flag!=1);
}
BIRGE-VIETA METHOD
This is written by Amisha
Coefficient x[3] = 1
Coefficient x[2] = 1
Coefficient x[1] = -3
Coefficient x[0] = -3
2.000000
{
printf("\nx%d=%f\t",i,x[i]); }
return(0);
}
A[1][1] : 10
A[1][2] : -7
A[1][3] : 3
A[1][4] : 5
A[2][1] : -6
A[2][2] : 8
A[2][3] : 4
A[2][4] : 7
A[3][1] : 2
A[3][2] : 6
A[3][3] : 9
A[3][4] : -1
The solution is:
x1=-7.809084
x2=-8.690902
x3=7.418177
3
45
6
7
8
9
Enter the allowed error and maximum number of iteration:
0.001
4
Iteration x[1] x[2]
1 2.0000 -0.6250
Converses in 1 iteration
a[ 1]= 2.0000
a[ 2]=-0.6250
}
h=x[2]-x[1];
printf("Please enter the value of x for which you want to print y: ");
scanf("%f",&f);
p=1;
d=y[1];
s=(f-x[1])/h;
for(int i=1;i<=n-1;i++){
for(int j=1;j<=(n-i);j++){
y[j]=y[j+1]-y[j];
}
p=p*(s-i+1)/i;
d=d+p*y[1];
}
printf("For the value of x(%f) the value of y is %0.4f",f,d);
}
This program is written by Amisha
Enter the value of n (number of terms you want to enter): 4
Enter the elements of x
4
3
4
5
Enter the elements of y
6
7
8
7
6
6
Please enter the value of x for which you want to print y: 3
For the value of x(3.000000) the value of y is 7.0000
#include<stdio.h>
#include<math.h>
float f(float x,float y);
int main()
{
float x0,y0,m1,m2,m3,m4,m,y,x,h,xn;
printf(“this code is written by Amisha\n”);
printf("Enter x0,y0,xn,h:");
scanf("%f %f %f %f",&x0,&y0,&xn,&h);
x=x0;
y=y0;
printf("\n\nX\t\tY\n");
while(x<xn)
{
m1=f(x0,y0);
m2=f((x0+h/2.0),(y0+m1*h/2.0));
m3=f((x0+h/2.0),(y0+m2*h/2.0));
m4=f((x0+h),(y0+m3*h));
m=((m1+2*m2+2*m3+m4)/6);
y=y+m*h;
x=x+h;
printf("%f\t%f\n",x,y);
}
}
float f(float x,float y)
{
float m;
m=(x-y)/(x+y);
return m;
}
This code is written by Amisha
Enter x0,y0,xn,h:0
2
2
0.5
X Y
0.500000 1.621356
1.000000 1.242713
1.500000 0.864069
2.000000 0.485426
0.000000 1.000000
0.050000 1.051345
0.100000 1.105579