Newton Rapson
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main(void)
{
double x = 3;
double fact1, fact2,ans;
double new_value,old,error=1;
for (int i = 0; i <= 10; i++)
{
ans = ((x * x * x) - 20) / 3 * (x * x);
if (error <= 0.009)
{
printf("\nCompleted");
break;
}
else
{
fact1 = (x * x * x) - 20;
fact2 = 3 * (x * x);
ans = fact1 / fact2;
ans = x - ans;
old = x;
x = ans;
new_value = ans;
printf("\nans: %f\n", ans);
error = ((new_value - old) / new_value) * 100;
error = abs(error);
printf("\npercentage:%f\n", error);
}
}
getche();
}
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main(void)
{
double x = 3;
double fact1, fact2,ans;
double new_value,old,error=1;
for (int i = 0; i <= 10; i++)
{
ans = ((x * x * x) - 20) / 3 * (x * x);
if (error <= 0.009)
{
printf("\nCompleted");
break;
}
else
{
fact1 = (x * x * x) - 20;
fact2 = 3 * (x * x);
ans = fact1 / fact2;
ans = x - ans;
old = x;
x = ans;
new_value = ans;
printf("\nans: %f\n", ans);
error = ((new_value - old) / new_value) * 100;
error = abs(error);
printf("\npercentage:%f\n", error);
}
}
getche();
}
No comments:
Post a Comment