You are on page 1of 2

#include<stdio.

h>
#include<conio.h>
#include<math.h>
#define f(Wp) (.12*S1)*Wp*Wp*Wp+(.64*S1-35.1*D)*Wp*Wp-(70.2*We)*Wp-(35.1*D*We*We
)
#define fd(Wp) (.36*S1)*Wp*Wp+(1.28*S1-70.2*D)*Wp-(70.2*We)
#define E 0.0005
main()
{
//D=400-600m;G=27kN/m3;We=5.0-6.0m;m=3m;SF=1.3;
//After Putting the values of above parameters the cubic equation converges to
//(.12S1)Wp^3+(.64S1-35.1D)Wp^2-(70.2We)Wp-(35.1DWe^2)
float D, We;
float sum=0.0;
float a[4]={.8,.16,.24,.3};
float sigma_a[4]={25,20,17,15};
for(int i=0;i<4;i++)
{
sum+=log(a[i])/2+log(sigma_a[i]);
}
sum=sum/4;
float k=exp(sum);
float S1=k;
printf("\n Enter the value of D(within the range 400-600): ");
scanf("%f", &D);
printf("\n Enter the value of We(within the range 5-6): ");
scanf("%f", &We);
main()
{
float Wp0, Wp1, f0, fd0, e;
printf("\t\t\t-Newton-Raphson Method-");
printf("\n\n To Find the Root of (.12S1)Wp^3+(.64S1-35.1D)Wp^2-(70.2We)Wp-(35.1D
We^2)");
printf("\n Enter the initial guess: ");
scanf("%f", &Wp0);
printf("\n f(Wp0)\t\t\t\t\tfd(Wp0)\t\t\t\t\tWp1\t\t\t\t\tError");
printf("\n -------------------------------------------------------------------------------------------");
begin:
f0 = f(Wp0);
fd0 = fd(Wp0);
Wp1 = Wp0 - (f0/fd0);
e =fabs((Wp1-Wp0)/Wp1);
if( e < E){
printf("\n\n Approx. Root = %.5f", Wp1);
}
else{
printf("\n %.2f\t%.3f\t%.3f\t%.4f",f(Wp0),fd(Wp0
),Wp1,e);
Wp0 = Wp1;
goto begin;
}

getch();
}

You might also like