
| (1) |
| (2) |
| (3) |
#include <stdio.h>
#include <math.h>
int main()
{
float a, b, c, disc,x1, x2;
a=1.0;b=200000;c=-3;
disc=b*b-4*a*c;
x1=(-b-sqrt(disc))/(2*a);
x2=(-b+sqrt(disc))/(2*a);
printf("x1 = %f, x2 = %f\n",x1,x2);
return 0;
}
|
|
|
|
| (11) |
| (12) |
|
| (16) |
| (17) |
| (18) |
/* Compute the square root of 2 */
#include <stdio.h>
#include <math.h>
#define EPS 1.0e-10
#define N 100
double f(double x)
{
return pow(x,2)-2;
}
/* start of main */
int main()
{
double x1, x2, x3;
int count;
printf("Enter xleft and xright separated by space =");
scanf("%lf %lf", &x1, &x2);
/* sanity check */
if (f(x1)*f(x2)>0) {printf("Invalid x1 and x2 !\n"); return 0;}
/* bisection start */
for (count=0;count< N; count++)
{
x3= (x1+x2)/2.0;
if (f(x1)*f(x3)<0 ) x2=x3; else x1=x3;
if ( f(x3)==0.0 || fabs(x1-x2)< EPS ) break;
}
printf("iteration = %d\n", count);
printf("x= %lf\n", x1);
return 0;
}
|
The equation of a straight line that passes (a,b) with a slope of m is
|
so the tangent line that passes (x1, f(x1)) with the slope of f ′(x1) is
|
|
|
|
|
|
| (19) |
|
|
|
|
|
|
|
| (30) |
| (31) |
| (32) |
| (33) |
| (34) |
| (35) |
|
| (38) |
|
| n | 10 | 12 | 14 | 16 | 18 | 20 |
| Time | 0.4 sec. | 1 min. | 3.6 hrs. | 41 days | 38 years | 16,000 years |