SlideShare ist ein Scribd-Unternehmen logo
1 von 4
/* Write C program to implement the Newton- Gregory forward interpolation.*/



#include<stdio.h>

#include<conio.h>

#define MaxN 100

#define Order_of_diff 4



void main ()

{

float arr_x[MaxN+1], arr_y[MaxN+1], numerator=1.0, denominator=1.0, x, y, p, h,
diff_table[MaxN+1][Order_of_diff+1];

int i,j,n,k;

clrscr();



printf("Enter the value of n n");

scanf("%d",&n);

printf("Enter the values of x and y");



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

scanf("%f%f", &arr_x[i], &arr_y[i]);

printf("Enter the value of x at which value of y is to be calculated");

scanf("%f", &x);

h=arr_x[1]-arr_x[0];



for(i=0; i<=n-1; i++)
diff_table[i][1]=arr_y[i+1]-arr_y[i];/*Creating the difference table and calculating first order
differences*/

for(j=2; j<=Order_of_diff; j++)/*Calculating higher order differences*/

for(i=0; i<=n-j; i++)

diff_table[i][j]=diff_table[i+1][j-1] - diff_table[i][j-1];

i=0;



while(!(arr_x[i]>x)) /* Finding x0 */

i++;

i--;

p=(x-arr_x[i])/h;

y=arr_y[i];



for (k=1; k<=Order_of_diff; k++)

{

    numerator *=p-k+1;

    denominator *=k;

    y +=(numerator/denominator)*diff_table[i][k];

}

printf("When x=%6.1f, y=%6.2fn",x, y);

getch();

}
/* Write C program to implement the Lagrange interpolation.*/



#include<stdio.h>

#include<conio.h>

#define MaxN 90



void main()

{

float arr_x[MaxN+1], arr_y[MaxN+1], numerator, denominator, x, y=0;

int i, j, n;

clrscr();

printf("Enter the value of n: n");

scanf("%d", &n);

printf("Enter the values of x and y: n");

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

scanf("%f%f", &arr_x[i], &arr_y[i]);

printf("Enter the value of x at which value of y is to be calculated: ");

scanf("%f", &x);

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

{

    numerator=1;

    denominator=1;

    for (j=0; j<=n; j++)
if(j!=i)

    {

    numerator *= x-arr_x[j];

    denominator *= arr_x[i]-arr_x[j];

    }

    y+=(numerator/denominator)*arr_y[i];

}

printf("When x=%4.1f y=%7.1fn",x,y);

getch();

}

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

week-5x
week-5xweek-5x
week-5x
 
Bcsl 033 data and file structures lab s1-1
Bcsl 033 data and file structures lab s1-1Bcsl 033 data and file structures lab s1-1
Bcsl 033 data and file structures lab s1-1
 
Metnum
MetnumMetnum
Metnum
 
C program to add n numbers
C program to add n numbers C program to add n numbers
C program to add n numbers
 
Bcsl 033 data and file structures lab s2-2
Bcsl 033 data and file structures lab s2-2Bcsl 033 data and file structures lab s2-2
Bcsl 033 data and file structures lab s2-2
 
Program in ‘C’ language to implement linear search using pointers
Program in ‘C’ language to implement linear search using pointersProgram in ‘C’ language to implement linear search using pointers
Program in ‘C’ language to implement linear search using pointers
 
C programming codes for the class assignment
C programming codes for the class assignmentC programming codes for the class assignment
C programming codes for the class assignment
 
Bcsl 033 data and file structures lab s2-3
Bcsl 033 data and file structures lab s2-3Bcsl 033 data and file structures lab s2-3
Bcsl 033 data and file structures lab s2-3
 
Write a program to perform translation.
 Write a program to perform translation. Write a program to perform translation.
Write a program to perform translation.
 
week-23x
week-23xweek-23x
week-23x
 
Write a program to perform translation
Write a program to perform translationWrite a program to perform translation
Write a program to perform translation
 
Shan
ShanShan
Shan
 
week-11x
week-11xweek-11x
week-11x
 
Bcsl 033 data and file structures lab s2-1
Bcsl 033 data and file structures lab s2-1Bcsl 033 data and file structures lab s2-1
Bcsl 033 data and file structures lab s2-1
 
Bcsl 033 data and file structures lab s5-2
Bcsl 033 data and file structures lab s5-2Bcsl 033 data and file structures lab s5-2
Bcsl 033 data and file structures lab s5-2
 
week-4x
week-4xweek-4x
week-4x
 
Progr3
Progr3Progr3
Progr3
 
C program to add two numbers
C program to add two numbers C program to add two numbers
C program to add two numbers
 
Examples sandhiya class'
Examples sandhiya class'Examples sandhiya class'
Examples sandhiya class'
 
week-18x
week-18xweek-18x
week-18x
 

Andere mochten auch (7)

ch17
ch17ch17
ch17
 
ch14
ch14ch14
ch14
 
week-1x
week-1xweek-1x
week-1x
 
week-10x
week-10xweek-10x
week-10x
 
BrainFingerprintingpresentation
BrainFingerprintingpresentationBrainFingerprintingpresentation
BrainFingerprintingpresentation
 
ch16
ch16ch16
ch16
 
DISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENT
DISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENTDISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENT
DISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENT
 

Ähnlich wie week-22x

Numerical analysis
Numerical analysisNumerical analysis
Numerical analysis
Vishal Singh
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
Azhar Javed
 
C basics
C basicsC basics
C basics
MSc CST
 

Ähnlich wie week-22x (20)

C Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossainC Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossain
 
DAA Lab File C Programs
DAA Lab File C ProgramsDAA Lab File C Programs
DAA Lab File C Programs
 
C lab manaual
C lab manaualC lab manaual
C lab manaual
 
BCSL 058 solved assignment
BCSL 058 solved assignmentBCSL 058 solved assignment
BCSL 058 solved assignment
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
C Programming
C ProgrammingC Programming
C Programming
 
Common problems solving using c
Common problems solving using cCommon problems solving using c
Common problems solving using c
 
Pnno
PnnoPnno
Pnno
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 
Computer graphics lab assignment
Computer graphics lab assignmentComputer graphics lab assignment
Computer graphics lab assignment
 
SaraPIC
SaraPICSaraPIC
SaraPIC
 
Assignment on Numerical Method C Code
Assignment on Numerical Method C CodeAssignment on Numerical Method C Code
Assignment on Numerical Method C Code
 
All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkar
 
Let us C (by yashvant Kanetkar) chapter 3 Solution
Let us C   (by yashvant Kanetkar) chapter 3 SolutionLet us C   (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 Solution
 
Numerical analysis
Numerical analysisNumerical analysis
Numerical analysis
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
 
programs
programsprograms
programs
 
C basics
C basicsC basics
C basics
 
Struct examples
Struct examplesStruct examples
Struct examples
 
C lab
C labC lab
C lab
 

Mehr von KITE www.kitecolleges.com (18)

ch6
ch6ch6
ch6
 
PPT (2)
PPT (2)PPT (2)
PPT (2)
 
holographic versatile disc
holographic versatile discholographic versatile disc
holographic versatile disc
 
week-16x
week-16xweek-16x
week-16x
 
week-6x
week-6xweek-6x
week-6x
 
week-3x
week-3xweek-3x
week-3x
 
ch8
ch8ch8
ch8
 
Intro Expert Systems test-me.co.uk
Intro Expert Systems test-me.co.ukIntro Expert Systems test-me.co.uk
Intro Expert Systems test-me.co.uk
 
ch4
ch4ch4
ch4
 
week-7x
week-7xweek-7x
week-7x
 
week-9x
week-9xweek-9x
week-9x
 
week-14x
week-14xweek-14x
week-14x
 
AIRBORNE
AIRBORNEAIRBORNE
AIRBORNE
 
ch2
ch2ch2
ch2
 
week-2x
week-2xweek-2x
week-2x
 
ch3
ch3ch3
ch3
 
Entity Classes and Attributes
Entity Classes and AttributesEntity Classes and Attributes
Entity Classes and Attributes
 
week-20x
week-20xweek-20x
week-20x
 

Kürzlich hochgeladen

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Kürzlich hochgeladen (20)

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 

week-22x

  • 1. /* Write C program to implement the Newton- Gregory forward interpolation.*/ #include<stdio.h> #include<conio.h> #define MaxN 100 #define Order_of_diff 4 void main () { float arr_x[MaxN+1], arr_y[MaxN+1], numerator=1.0, denominator=1.0, x, y, p, h, diff_table[MaxN+1][Order_of_diff+1]; int i,j,n,k; clrscr(); printf("Enter the value of n n"); scanf("%d",&n); printf("Enter the values of x and y"); for(i=0; i<=n; i++) scanf("%f%f", &arr_x[i], &arr_y[i]); printf("Enter the value of x at which value of y is to be calculated"); scanf("%f", &x); h=arr_x[1]-arr_x[0]; for(i=0; i<=n-1; i++)
  • 2. diff_table[i][1]=arr_y[i+1]-arr_y[i];/*Creating the difference table and calculating first order differences*/ for(j=2; j<=Order_of_diff; j++)/*Calculating higher order differences*/ for(i=0; i<=n-j; i++) diff_table[i][j]=diff_table[i+1][j-1] - diff_table[i][j-1]; i=0; while(!(arr_x[i]>x)) /* Finding x0 */ i++; i--; p=(x-arr_x[i])/h; y=arr_y[i]; for (k=1; k<=Order_of_diff; k++) { numerator *=p-k+1; denominator *=k; y +=(numerator/denominator)*diff_table[i][k]; } printf("When x=%6.1f, y=%6.2fn",x, y); getch(); }
  • 3. /* Write C program to implement the Lagrange interpolation.*/ #include<stdio.h> #include<conio.h> #define MaxN 90 void main() { float arr_x[MaxN+1], arr_y[MaxN+1], numerator, denominator, x, y=0; int i, j, n; clrscr(); printf("Enter the value of n: n"); scanf("%d", &n); printf("Enter the values of x and y: n"); for(i=0; i<=n; i++) scanf("%f%f", &arr_x[i], &arr_y[i]); printf("Enter the value of x at which value of y is to be calculated: "); scanf("%f", &x); for (i=0; i<=n; i++) { numerator=1; denominator=1; for (j=0; j<=n; j++)
  • 4. if(j!=i) { numerator *= x-arr_x[j]; denominator *= arr_x[i]-arr_x[j]; } y+=(numerator/denominator)*arr_y[i]; } printf("When x=%4.1f y=%7.1fn",x,y); getch(); }