1. Trang chủ
  2. » Công Nghệ Thông Tin

A textbook of Computer Based Numerical and Statiscal Techniques part 59 ppsx

10 174 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 10
Dung lượng 90,34 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

13.4 ALGORITHM FOR FALSE POSITION METHOD Step 1.. Start of the program to compute the real root of the equation Step 2.. Continue the process step 5 to step 9 till to get required accura

Trang 1

b = x1;

}

x1 = (a + b)/2;

printf(“%f”,x1);

}

The root of the given equation is 1.5121

13.4 ALGORITHM FOR FALSE POSITION METHOD

Step 1 Start of the program to compute the real root of the equation

Step 2 Input the value of x0, x1 and e

Step 3 Check f(x0) × f(x1) < 0

Step 4 If no, print “Error” and exit

Step 5 If yes, compute x2 = x f x x f x

f x f x

> C > C

> C > C−−

Step 6 Compute f(x2)

Step 7 Again, if f(x2) × f(x0) < 0

Step 8 Set x1 = x2

Step 9 Else, set x0 = x2

Step 10 Continue the process step 5 to step 9 till to get required accuracy

Step 11 Print output

Step 12 End of the program

13.5 PROGRAMMING FOR FALSE POSITION METHOD

(1) Find the Real Root of the Given Equation x3 – 2x – 5 = 0

#include<conio.h>

#include<stdio.h>

#include<math.h>

void false(float, float);

void main()

{

float x0 = 3, x1 = 4;

clrscr();

false(x0, x1);

getch();

}

void false(float x0, float x1)

{

Trang 2

int i;

float x2 = 0, a = 0, b = 0, c = 0;

for(i = 0; i < 12; i++)

{

a = pow(x0, 3)–2*x0–5;

b = pow(x1, 3)–2*x1–5;

x2 = x0–(x1–x0)/(b–a)*a);

c = pow(x2, 3)–2*x2–5;

if(c < 0)

x0 = x2;

else

x1 = x2;

}

printf(“%f”, x2);

}

The root of the given equation is 2.094

(2) Find the Real Root of the Given Equation 3x + sin x – ex = 0

#include<conio.h>

#include<stdio.h>

#include<math.h>

float flase(float, float);

void main()

{

float a, x0 = 0, x1 = 1, b, x2;

clrscr();

a = false(x0, x1);

b = false(x2);

printf(“%f”, b);

getch();

}

float false(float x0, float x1)

{

float x2;

int i;

for(i = 1; i <= 13; i++)

{

y0 = 3*x0 + sin(x0)–pow(2.7187, x0);

y1 = 3*x1 + sin(x1)–pow(2.7187, x1);

x2 = x0–(x1–x0)/(y1–y0)*y0;

y2 = 3*x2 + sin(x2) – pow(2.7187, x2);

if(y2 < 0)

Trang 3

x0 = x2;

else

x1 = x2;

}

return (x2);

}

The root of the given equation is 36042

13.6 ALGORITHM FOR ITERATION METHOD

Step 1 Start of the program to compute the real root of the equation

Step 2 Input the value of x0 (initial guess)

Step 3 Input the value of required alllowed error e

Step 4 Input the total iteration to be allowed n

Step 5 Compute φ(x0), x1 ← φ(x0)

(step 7 to 8 are repeated until the procedure converges to a root) Step 6 For i = 1 to n, in step 2 to step 4 do

Step 7 x0 ← x1, x1 ←φ(x0)

Step 8 If x x

x

1 0 1

≤ e then GOTO step 11

end for Step 9 Print “does not converge to a root”, x0, x1

Step 10 Stop

Step 11 Print “converge to a roof ”, i, x1

Step 12 End of the program

13.7 PROGRAMMING FOR ITERATION METHOD

(1) Find the Real Root of the Given Equation xex = 1

#include<conio.h>

#include<stdio.h>

#include<math.h>

void main()

{

void iterat(float);

int i, j;

float x0, a;

clrscr();

Trang 4

a = 0.5;

x0 = a;

iterat(x0);

getch();

}

void iterat(float x0)

{

int i;

float x1, x2;

for(i = 1; i <= 12; i++)

{

x1 = 1/pow(e, x0);

x2 = 1/pow(e, x1);

x0 = x2;

}

print(“The result is: %f”, x2);

}

The root of the given equation is 0.5671

(2) Find the Real Root of the Given Equation 2x –log10 x = 7

#include<conio.h>

#include<stdio.h>

#include<math.h>

void main()

{

void iterat(float);

int i, j;

float x0, a;

clrscr();

a = 3.7;

x0 = a;

iterat(x0);

getch();

}

void iterat(float x0)

{

int i;

float x1, x2;

for(i = 1; i <= 12; i++)

{

Trang 5

x1 = (7 + log(x0)/2;

x2 = (7 + log(x1)/2;

x0 = x2;

}

print(“The result is: %f”, x2);

}

The root of the given equation is 4.2199

(3) Find the Real Root of the Given Equation x sin x = 1

#include<conio.h>

#include<stdio.h>

#include<math.h>

void main()

{

void iterat(float);

int i, j;

float x0, a;

clrscr();

a = 1.5;

x0 = a;

iterat(x0);

getch();

}

void iterat (float x0)

{

int i;

float x1, x2;

for (i = 1; i <= 12; i++)

{

x1 = 1/sin (x0);

x2 = 1/sin (x1);

x0 = x2;

}

printf(“The result is: %f”, x2);

}

The root of the given equation is 1.114

(4) Find the Real Root of the Given Equation 2x – log10 x = 7

#include<stdio.h>

#include<conio.h>

#include<math.h>

Trang 6

float iteration(float);

void main()

{

float a;

float x = 3.7;

clrscr();

a = iteration(x);

printf(“%f”, a);

getch();

}

float iteration(float x)

{

int i;

float s = 0;

for(i = 0; i < 15; i++) {

s = 0.5*(7 + log(x));

x = s;

}

return(s);

}

The root of the given equation is 4.2199

13.8 ALGORITHM FOR NEWTON’S RAPHSON METHOD

Step 1 Start of the program to compute the real root of the equation

Step 2 Input the value of x0, n and e

Step 3 For i = 1 and repeat if i < = n

Step 4 f 0 = f(x0)

Step 5 df 0 = df(x0)

Step 6 Compute x1 = x0 – (f 0/df 0)

Step 6a If x x

x

1

< e Step 6b Print “convergent”

Step 6c Print x1, f(x1), i

Step 7 End of the program

Step 8 Else, Set x0 = x1

Step 9 Repeat the process until to get required accuracy

Step 10 End of the program

Trang 7

13.9 PROGRAMMING FOR NEWTON RAPHSON METHOD

(1) Find the Real Root of the Given Equation x2 = 12

//program-netwon raphson

#include<conio.h>

#include<stdio.h>

#include<math.h>

float f(float x)

{

return((x*x)–(12));

}

float d(float x)

{

return((2*x));

}

void main()

{

float x, y, s;

int i, c = 0;

clrscr();

for(i = 0; ; i++)

{

if(f(i) > 0) break;

}

x = i;

aa:

{

++c;

y = x–(f(x)/d(x));

x = y;

s = (y*10000);

printf(“\nthe position of iteration %d”, c);

printf(“\nthe root is %f”, y);

y = (y*10000);

if(y != s) goto aa;

}

printf(“\nreal root is %f”,y);

getch();

}

The root of the given equation is 3.4641

Trang 8

(2) Find the Real Root of the Given Equation x2 – 5x + 2 = 0

//program-netwon raphson

#include<conio.h>

#include<stdio.h>

#include<math.h>

float f(float x)

{

return((x*x) – (5*x) + 2;

}

float d(float x)

{

return((2*x) – 5);

}

void main()

{

float x, y = 0;

int i;

clrscr();

for(i = 0;; i++)

{

if(f(i) > 0) break;

}

x = i;

for(i = 0; i < 10; i++)

{

y = x–f(x)/d(x);

x = y;

printf(“\nreal root is %f”, y);

}

getch();

}

The root of the given equation is 0.438447

(1) Find the Real Root of the Given Equation x3 – x2 – x – 1 = 0

#include<conio.h>

#include<stdio.h>

Trang 9

void main()

{

int i, j;

flat x0, x1, x2, x3, y0, y1, y2, a, b;

float val(float);

clrscr();

x0 = 1.9;

x1 = 2.0;

x2 = 2.1;

for(i = 0; i < 3; i++) {

y0 = val(x0);

y1 = val(x1);

y2 = val(x2);

a = ((x0–x1)*(y1–y2)–(x1–x2)) (y0–y2))/((x1–x0)*(x1–x2)*(x0–x2));

b = (pow((x0–x1), 2)*(y1–y2)–pow((x1–x2), 2)*(y0–y2))/((x0–x1)*(x1–x2)*(x0–x2)); x3 = x2–((2*y2)/(b + pow((pow(b, 2)–4*a*y2), 5)));

x0 = x1;

x1 = x2;

x2 = x3;

} printf(“%f”, x3);

getch();

}

float val(float x)

{

float y;

y = pow(x, 3) – pow(x, 2) – x – 1;

return(y);

}

The root of the given equation is 1.8382067

(2) Find the Real Root of the Given Equation x3 – 3x – 5 = 0

#include<conio.h>

#include<stdio.h>

#include<math.h>

void main()

{

int i, j;

float x0, x1, x2, x3, y0, y1, y2, a, b;

Trang 10

float val(float);

clrscr();

x0 = 1.9;

x1 = 2.0;

x2 = 2.7;

for(i = 0; i < 3; i++) {

y0 = val(x0);

y1 = val(x1);

y2 = val(x2);

a = ((x0–x1)*(y1–y2)–(x1–x2)*(y0–y2))/((x1–x0)*(x1–x2)*(x0–x2));

b = (pow((x0–x1), 2)*(y1–y2)–(pow(x1–x2), 2)*(y0–y2))/((x0–x1)*(x1–x2)*(x0–x2)); x3 = x2–((2*y2)/(b + pow((pow(b, 2)–4*a*y2), 5)));

x0 = x1;

x1 = x2;

x2 = x3;

}

printf(“%f”, x3);

getch();

}

float val(float x)

{

float y;

y = pow(x, 3)–(3* x) –5;

return(y);

}

The root of the given equation is 2.417728

METHOD

Step 1 Start of the program to interpolate the given data

Step 2 Input the value of n (number of terms)

Step 3 Input the array ax for data of x

Step 4 Input the array ay for data of y

Step 5 Compute h = ax[1] – ax[0]

Step 6 For i = 0; i < n–1; i++

Step 7 diff[i] [1] = ay[i+1]–ay[i]

Step 8 End of the loop i

Step 9 For j = 2; j <= 4; j++

Ngày đăng: 04/07/2014, 15:20

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN