목차
1. Source code
2. result
2. result
본문내용
2 = p1 - f(p1)*(p1-p0)/(f(p1)-f(p0));
p0 = p1;
p1 = p2;
n++;
printf("n= %d Pn= %f f(Pn)= %f \n",n,p2,f(p2));
}
printf("Solution is %f\n",p2);
return 0;
}
float f(float x)
{
return x*x*x - 2*x*x -5;
}
float absol(float x)
{
if(x>=0)return x;
else return (-1) * x;
}
(2)Result
2.3-3.b
(1) Source code
/*
I will start the Secant method at p0=-3 , p1=-2
for the value of x with x^3 + 3x^2 - 1 = 0
*/
#include
#include
#define TOL 0.0001
float f(float x);
float absol(float x);
main()
{
int n;
float p0, p1, p2;
n = 1;
p0 = -3;
p1 = -2;
p2 = 0;
while(absol(p1-p0)>=TOL)
{
p2 = p1 - f(p1)*(p1-p0)/(f(p1)-f(p0));
p0 = p1;
p1 = p2;
n++;
printf("n= %d Pn= %f f(Pn)= %f \n",n,p2,f(p2));
}
printf("Solution is %f\n",p2);
return 0;
}
float f(float x)
{
return x*x*x + 3*x*x -1;
}
float absol(float x)
{
if(x>=0)return x;
else return (-1) * x;
}
(2)Result
2.3-3.c
(1) Source code
/*
I will start the Secant method at p0=0 , p1=pi/2
for the value of x with x - cos(x) = 0
*/
#include
#include
#define TOL 0.0001
#define pi 3.141592
float f(float x);
float absol(float x);
main()
{
int n;
float p0, p1, p2;
n = 1;
p0 = 0;
p1 = pi/2;
p2 = 0;
while(absol(p1-p0)>=TOL)
{
p2 = p1 - f(p1)*(p1-p0)/(f(p1)-f(p0));
p0 = p1;
p1 = p2;
n++;
printf("n= %d Pn= %f f(Pn)= %f \n",n,p2,f(p2));
}
printf("Solution is %f\n",p2);
return 0;
}
float f(float x)
{
return x - cos(x);
}
float absol(float x)
{
if(x>=0)return x;
else return (-1) * x;
}
(2)Result
2.3-3.d
(1) Source code
/*
I will start the Secant method at p0=0 , p1=pi/2
for the value of x with x - 0.8 - 0.2sin(x) = 0
*/
#include
#include
#define TOL 0.0001
#define pi 3.141592
float f(float x);
float absol(float x);
main()
{
int n;
float p0, p1, p2;
n = 1;
p0 = 0;
p1 = pi/2;
p2 = 0;
while(absol(p1-p0)>=TOL)
{
p2 = p1 - f(p1)*(p1-p0)/(f(p1)-f(p0));
p0 = p1;
p1 = p2;
n++;
printf("n= %d Pn= %f f(Pn)= %f \n",n,p2,f(p2));
}
printf("Solution is %f\n",p2);
return 0;
}
float f(float x)
{
return x - 0.8 - 0.2*sin(x);
}
float absol(float x)
{
if(x>=0)return x;
else return (-1) * x;
}
(2)Result
HW#5
2.3-9
(1) Source code
/*
I sketched the graph of f(x)=x^2 -3 and I concluded that
I will start the Secant method at a=1 , b=2
for the value of x with x= sqrt(3)
*/
#include
#include
#define TOL 0.0001
float f(float x);
float absol(float x);
main()
{
int n;
float p0, p1, p2;
n = 1;
p0 = 1;
p1 = 2;
p2 = 0;
while(absol(p1-p0)>=TOL)
{
p2 = p1 - f(p1)*(p1-p0)/(f(p1)-f(p0));
p0 = p1;
p1 = p2;
n++;
printf("n= %d Pn= %f f(Pn)= %f \n",n,p2,f(p2));
}
printf("Solution is %f\n",p2);
return 0;
}
float f(float x)
{
return x*x - 3;
}
float absol(float x)
{
if(x>=0)return x;
else return (-1) * x;
}
(2)Result
(3) Compare to 2.2-9
I used the Bisection method for excercise 2.2-9, and
I used the Secant method for excercise 2.3-9.
The number of iteration was different each other.
- n -
Bisection method : 14 times
Secant method : 5 times
Therefore, Secant method is more efficient than Bisectoin method.
p0 = p1;
p1 = p2;
n++;
printf("n= %d Pn= %f f(Pn)= %f \n",n,p2,f(p2));
}
printf("Solution is %f\n",p2);
return 0;
}
float f(float x)
{
return x*x*x - 2*x*x -5;
}
float absol(float x)
{
if(x>=0)return x;
else return (-1) * x;
}
(2)Result
2.3-3.b
(1) Source code
/*
I will start the Secant method at p0=-3 , p1=-2
for the value of x with x^3 + 3x^2 - 1 = 0
*/
#include
#include
#define TOL 0.0001
float f(float x);
float absol(float x);
main()
{
int n;
float p0, p1, p2;
n = 1;
p0 = -3;
p1 = -2;
p2 = 0;
while(absol(p1-p0)>=TOL)
{
p2 = p1 - f(p1)*(p1-p0)/(f(p1)-f(p0));
p0 = p1;
p1 = p2;
n++;
printf("n= %d Pn= %f f(Pn)= %f \n",n,p2,f(p2));
}
printf("Solution is %f\n",p2);
return 0;
}
float f(float x)
{
return x*x*x + 3*x*x -1;
}
float absol(float x)
{
if(x>=0)return x;
else return (-1) * x;
}
(2)Result
2.3-3.c
(1) Source code
/*
I will start the Secant method at p0=0 , p1=pi/2
for the value of x with x - cos(x) = 0
*/
#include
#include
#define TOL 0.0001
#define pi 3.141592
float f(float x);
float absol(float x);
main()
{
int n;
float p0, p1, p2;
n = 1;
p0 = 0;
p1 = pi/2;
p2 = 0;
while(absol(p1-p0)>=TOL)
{
p2 = p1 - f(p1)*(p1-p0)/(f(p1)-f(p0));
p0 = p1;
p1 = p2;
n++;
printf("n= %d Pn= %f f(Pn)= %f \n",n,p2,f(p2));
}
printf("Solution is %f\n",p2);
return 0;
}
float f(float x)
{
return x - cos(x);
}
float absol(float x)
{
if(x>=0)return x;
else return (-1) * x;
}
(2)Result
2.3-3.d
(1) Source code
/*
I will start the Secant method at p0=0 , p1=pi/2
for the value of x with x - 0.8 - 0.2sin(x) = 0
*/
#include
#include
#define TOL 0.0001
#define pi 3.141592
float f(float x);
float absol(float x);
main()
{
int n;
float p0, p1, p2;
n = 1;
p0 = 0;
p1 = pi/2;
p2 = 0;
while(absol(p1-p0)>=TOL)
{
p2 = p1 - f(p1)*(p1-p0)/(f(p1)-f(p0));
p0 = p1;
p1 = p2;
n++;
printf("n= %d Pn= %f f(Pn)= %f \n",n,p2,f(p2));
}
printf("Solution is %f\n",p2);
return 0;
}
float f(float x)
{
return x - 0.8 - 0.2*sin(x);
}
float absol(float x)
{
if(x>=0)return x;
else return (-1) * x;
}
(2)Result
HW#5
2.3-9
(1) Source code
/*
I sketched the graph of f(x)=x^2 -3 and I concluded that
I will start the Secant method at a=1 , b=2
for the value of x with x= sqrt(3)
*/
#include
#include
#define TOL 0.0001
float f(float x);
float absol(float x);
main()
{
int n;
float p0, p1, p2;
n = 1;
p0 = 1;
p1 = 2;
p2 = 0;
while(absol(p1-p0)>=TOL)
{
p2 = p1 - f(p1)*(p1-p0)/(f(p1)-f(p0));
p0 = p1;
p1 = p2;
n++;
printf("n= %d Pn= %f f(Pn)= %f \n",n,p2,f(p2));
}
printf("Solution is %f\n",p2);
return 0;
}
float f(float x)
{
return x*x - 3;
}
float absol(float x)
{
if(x>=0)return x;
else return (-1) * x;
}
(2)Result
(3) Compare to 2.2-9
I used the Bisection method for excercise 2.2-9, and
I used the Secant method for excercise 2.3-9.
The number of iteration was different each other.
- n -
Bisection method : 14 times
Secant method : 5 times
Therefore, Secant method is more efficient than Bisectoin method.
소개글