Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

Giải gần đúng phương trình (t.

t)
1. Phương pháp dây cung:
- Xét hàm số f(x)= x 4 −6 x +9
- Tách nghiệm: Phương trình có 1 nghiệm x(1;2)
- Chính xác hóa nghiệm:
o Ta có f(1) = 4 > 0 ; f(2) = -11 < 0
( 2−1 )∗4
o x 1=1− =1.267
−11−4
o f ( x )=f ( 1.267 )=1.896 >0
o Bảng kết quả:
a b x f(x)
1 2 1.267 +
1.267 1.267 +
1.375 1.375 +
1.419 1.419 +
1.436 1.436 +
1.444 1.444 +
1.447 1.447 +
1.448 1.448 +
1.448 1.448 +
1.448 1.448 +
1.449 1.449 +
1.449 1.449 +
1.449 1.449 +
1.449 1.449 +
1.449 1.449 +
#include<stdio.h>
#include<math.h>
//f(x)=x^4-6^x+9
float fx(float);
void bow(float, float, float);
char check(float);

int main(){
float a,b,x;
printf("Nhap can duoi: ");
scanf("%f",&a);
printf("Nhap can tren: ");
scanf("%f",&b);
x=a-((b-a)*fx(a))/(fx(b)-fx(a));
printf("a b x f(x)\n");
printf("----------------------------\n");
printf("%.3f %.3f %.3f %c\n",a,b,x,check(fx(x)));
bow(a,b,x);
}

float fx(float x){


return pow(x,4)-pow(6,x)+9;
}

char check(float fx){


if(fx<0) return '-';
else return '+';
}
void bow(float a, float b, float x){
while(fabs(fx(x))>1e-6){
x=a-((b-a)*fx(a))/(fx(b)-fx(a));
if(fx(x)*fx(a)<0){
b=x;
printf("----------------------------\n");
printf("%.3f %.3f %.3f %c\n",a,b,x,check(fx(x)));
}
else{
a=x;
printf("----------------------------\n");
printf("%.3f %.3f %.3f %c\n",a,b,x,check(fx(x)));
}
}
printf("------------------------------------------------\n");
printf("Nghiem cua phuong trinh la: %.3f\n",x);
printf("Gia tri cua phuong trinh voi x = %.3f la: %.3f",x,fx(x));
}

- Xét hàm số f(x)=−x 3 +ln ( x )+ e


- Tách nghiệm: Phương trình có 1 nghiệm x(1;2)
- Chính xác hóa nghiệm:
o Ta có f(1) = 1,718 > 0 ; f(2) = -4.589 < 0
( 2−1 )∗1.718
o x 1=1− =1.272
−4.589−1.718
o f ( x )=f ( 1.272 )=0.901> 0
o Bảng kết quả:
a b x f(x)
1.00 2.00 1.272 +
1.272 1.272 +
1.392 1.392 +
1.435 1.435 +
1.450 1.450 +
1.455 1.455 +
1.456 1.456 +
1.457 1.457 +
1.457 1.457 +
1.457 1.457 +
1.457 1.457 +
1.457 1.457 +
1.457 1.457 +
1.457 1.457 +
1.457 1.457 +
#include<stdio.h>
#include<math.h>
//f(x)=-x^3+ln(x)+e
float fx(float);
void bow(float, float, float);
char check(float);
const float e =2.718;

int main(){
float a,b,x;
printf("Nhap can duoi: ");
scanf("%f",&a);
printf("Nhap can tren: ");
scanf("%f",&b);
x=a-((b-a)*fx(a))/(fx(b)-fx(a));
printf("a b x f(x)\n");
printf("----------------------------\n");
printf("%.3f %.3f %.3f %c\n",a,b,x,check(fx(x)));
bow(a,b,x);
}

float fx(float x){


return e+log(x)-pow(x,3);
}

char check(float fx){


if(fx<0) return '-';
else return '+';
}
void bow(float a, float b, float x){
while(fabs(fx(x))>1e-6){
x=a-((b-a)*fx(a))/(fx(b)-fx(a));
if(fx(x)*fx(a)<0){
b=x;
printf("----------------------------\n");
printf("%.3f %.3f %.3f %c\n",a,b,x,check(fx(x)));
}
else{
a=x;
printf("----------------------------\n");
printf("%.3f %.3f %.3f %c\n",a,b,x,check(fx(x)));
}
}
printf("------------------------------------------------\n");
printf("Nghiem cua phuong trinh la: %.3f\n",x);
printf("Gia tri cua phuong trinh voi x = %.3f la: %.3f",x,fx(x));
}

2. Phương pháp tiếp tuyến:


- Xét hàm số f(x)= x 4 −6 x +9
- Tách nghiệm:
o f ( x )=4 x 3−6 x ln ( 6 )<0 x
lim f ( x ) =+∞ , lim f ( x )=−∞
o x→−∞ x→+∞

o Phương trình trên có 1 nghiệm duy nhất


o f(1)*f(2)<0
o Vậy phương trình có 1 nghiệm duy nhất x ( 1 , 2 )
o Chính xác hóa nghiệm:
 f (x)= {12x} ^ {2} - {6} ^ {x} {ln} ^ {2} (6 <0 x( 1 , 2 )
 f (x)>0
 Áp dụng phương pháp tiếp tuyến.
 Chọn với x 0=1.5 ta có bảng kết quả sau
x f(x)/f’(x)
1.500 0.049
1.449 0.002
1.449 0.000
1.449
Vậy nghiệm x1.516

#include <stdio.h>
#include <math.h>
// f(x)=x^4-6^x+9
float fx(float);
float fdhx(float);
void tt(float);

int main()
{
float x;
printf("Nhap x: ");
scanf("%f", &x);
printf("x f(x)/f'(x)\n");
printf("----------------------------\n");
printf("%.3f %.3f\n",x,fx(x)/fdhx(x));
tt(x);
}

float fx(float x)
{
return pow(x, 4) - pow(6, x) + 9;
}

float fdhx(float x)
{
return 4 * pow(x, 3) - pow(6, x) * log(6);
}

void tt(float x)
{
float y = x;
x = y - fx(y) / fdhx(y);
while (fabs(x - y) > 1e-4)
{
y = x;
x = y - fx(y) / fdhx(y);
printf("%.3f %.3f\n",x,fx(y)/fdhx(y));
}
printf("Nghiem cua phuong trinh la: %.3f\n",x);
printf("Ket qua cua phuong trinh voi x= %.3f la: %.3f",x,fx(x));
}

You might also like