program cbnst
program cbnst
3. PROGRAM
#include<stdio.h>
#include<math.h>
double fun1(double a)
{
double x = pow(a,3)-(4*a)-9;
return x;
}
int main()
{
2. METHOD
Step 1: Choose two initial values a and b such that f(a)×f(b)
Step 5: Stop the procedure when the desired accuracy is achieved, with xxx
being the root of the function.
OUTPUT:
The root is approximately: 1.800000
The root is approximately: 2.560117
The root is approximately: 2.688061
The root is approximately: 2.704286
The root is approximately: 2.706257
The root is approximately: 2.706495
The root is approximately: 2.706524
iteration = 7
2. METHOD
Algorithm
1. Define the Function and Its Derivative:
• Function f(x)=x3−4x−9f(x) = x^3 - 4x - 9f(x)=x3−4x−9
• Derivative f′(x)=3x2−4f'(x) = 3x^2 - 4f′(x)=3x2−4
2. Initialize Variables:
• Set an initial guess x0x_0x0.
• Define the tolerance level for convergence (0.0001).
• Set a maximum number of iterations to prevent infinite loops.
3. Perform Iterations:
• Compute f(x)f(x)f(x) and f′(x)f'(x)f′(x).
• Update the guess using the Newton-Raphson formula:
Xnew=x−f(x)/f′(x)
• Check for convergence: if the absolute difference between the new and
old guesses is less than the tolerance, the method has converged.
• Print each iteration's details.
• If the method does not converge within the maximum number of
iterations, output a message indicating failure.
OUTPUT:
For fn x3 -4x-9
2.PROGRAM:
#include<stdio.h>
#include<math.h>
int main()
{
float x,u1,u,y;
int i,j,n,fact;
printf("Enter no. of terms\n");
scanf("%d",&n);
float a[n][n+1];
printf("Enter Values of X\n");
for(i=0;i<n;i++)
scanf("%f",&a[i][0]);
printf("Enter Values of Y\n");
for(i=0;i<n;i++)
scanf("%f",&a[i][1]);
printf("Enter value of x for which you want y\n");
scanf("%f",&x);
for(j=2;j<n+1;j++)
{
for(i=0;i<n-j+1;i++)
a[i][j] = a[i+1][j-1]-a[i][j-1];
NAME-SHIV CHARAN SHARMA SECTION-G2 SEM.-5TH ROLL NO.-2219632(64)
}
printf("The Difference Table is as follows:\n");
for(i=0;i<n;i++)
{
for(j=0;j<=n-i;j++)
printf("%f ",a[i][j]);
printf("\n");
}
u= (x - a[0][0])/(a[1][0]-a[0][0]);
y=a[0][1];
u1=u;
fact=1;
for(i=2;i<=n;i++)
{
y=y+(u1*a[0][i])/fact;
fact=fact*i;
u1=u1*(u-(i-1));
}
printf("\n\nValue at X=%g is = %f", x,y);
2.PROGRAM:
#include<stdio.h>
#include<math.h>
int main()
{
float x,u1,u,y;
int i,j,n,fact;
printf("Enter no. of terms\n");
scanf("%d",&n);
float a[n][n+1];
printf("Enter Values of X \n");
for(i=0;i<n;i++)
scanf("%f",&a[i][0]);
printf("Enter Values of Y\n");
for(i=0;i<n;i++)
scanf("%f",&a[i][1]);
printf("Enter value of x for which you want y\n");
scanf("%f",&x);
for(j=2;j<n+1;j++)
{
for(i=0;i<n-j+1;i++)
NAME-SHIV CHARAN SHARMA SECTION-G2 SEM.-5TH ROLL NO.-2219632(64)
a[i][j] = a[i+1][j-1]-a[i][j-1];
}
printf("The Difference Table is as follows:\n");
for(i=0;i<n;i++)
{
for(j=0;j<=n-i;j++)
printf("%f ",a[i][j]);
printf("\n");
}
u= (x - a[n-1][0])/(a[1][0]-a[0][0]);
y=a[n-1][1];
u1=u;
fact=1;
j=2;
for(i=n-2;i>=0;i--)
{
y=y+(u1*a[i][j])/fact;
fact=fact*j;
u1=u1*(u+(j-1));
j++;
}
printf("\n\nValue at X=%g is=%f",x,y);
}