SlideShare a Scribd company logo
1 of 4
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
#define pi 3.1415926
const int n = 5; //number of input data points
double sum1 = 0, sum2 = 0, coeff = 1, p, X1, X2;
int h;
int factorial(int n)
{
int x=1;
while(n>=1)
{
x=x*n;
n--;
}
return x;
}
void forward_diff_table(double Y[][n])
{
int i, j;
for(j=1; j<n; j++) //compute values in the table
{
for(i=0; i<n-j; i++)
{
Y[i][j] = Y[i+1][j-1] - Y[i][j-1];
}
}
}
double forward_interpolation(double Y[][n])
{
double sum = 0;
for(int i=1; i<n; i++)
{
coeff = 1;
for(int j=1; j<=i; j++)
{
coeff = coeff*(p + 1 - j);
}
sum = sum + (coeff*Y[0][i])/factorial(i); //sum gives the
interpolated value at a given point
}
return sum;
}
void main()
{
clrscr();
double x[n]={10, 20, 30, 40, 50}; //x: input values in degrees
double Y[n][n]={{0.1736},{0.342},{0.5},{0.6428},{0.766}}; //Y stores
output values corresponding to the input AS WELL AS the difference table
h = x[1] - x[0]; //step size
forward_diff_table(Y);
int gdriver = DETECT, gmode;
initgraph(&gdriver, &gmode, "C:turboc3bgi"); //initialising
graphics
int max_x, max_y; //max_x = 639, max_y = 479
max_x = getmaxx();
max_y = getmaxy();
setcolor(15); //white colour
line(max_x/2,0 , max_x/2,max_y); //y axis
line(0,max_y/2 , max_x,max_y/2); //x axis
//plotting interpolating polynomial
setcolor(4); //red colour
setlinestyle(0,0,3);
int comp_y1, comp_y2;
for(int comp_x=0; comp_x<=max_x; comp_x++)
{
X1 = (comp_x - max_x/2.0)*360.0/(max_x/2.0); //cartesian x
(coordinate transformation from computer to cartesian)
p = (X1 - x[0])/h;
sum1 = forward_interpolation(Y) + Y[0][0]; //cartesian y
comp_y1 = max_y * (-sum1 + 3.0)/6.0; //computer y
(coordinate transformation from cartesian to computer)
X2 = (comp_x + 1 -max_x/2.0)*360.0/(max_x/2.0);
p = (X2 - x[0])/h;
sum2 = forward_interpolation(Y) + Y[0][0];
comp_y2 = max_y * (-sum2 + 3.0)/6.0;
line(comp_x,comp_y1 , comp_x+1,comp_y2); //drawing line
between two very very close points
}
//y = sinx
setcolor(14); //yellow colour
int X, y1, y2; //computer
coordinates
double cartesian_x1, cartesian_y1, cartesian_x2, cartesian_y2;
//cartesian coordinates
for(X=0; X<=max_x; X++)
{
cartesian_x1 = (X - max_x/2.0)*(2*pi)/(max_x/2.0); //coordinate
transformations (X,y1,y2: computer coordinates)
cartesian_y1 = sin(cartesian_x1); //f(x) = sinx
y1 = max_y*(-cartesian_y1 + 3.0)/6.0; //coordinate
transformations
cartesian_x2 = (X + 1 - max_x/2.0)*(2*pi)/(max_x/2.0);
cartesian_y2 = sin(cartesian_x2);
y2 = max_y*(-cartesian_y2 + 3.0)/6.0;
line(X,y1, X+1,y2); //draw line b/w (x,sinx) &
(x+1,sin(x+1))
}
setlinestyle(0,0,1);
setcolor(15); line(500,30 , 520,30); outtextxy(530,25,
"axes");
setlinestyle(0,0,3);
setcolor(14); line(500,60 , 520,60); outtextxy(530,55, "y =
sinx");
setcolor(4); line(500,90 , 520,90); outtextxy(530,85,
"interpolating"); outtextxy(530,95, "polynomial");
setcolor(1); fillellipse(502,120,2,2); outtextxy(520,115,
"input data"); outtextxy(520,125, "points");
setcolor(1);
for(int i=0; i<5; i++)
fillellipse(max_x*(x[i]+360)/(2.0*360), max_y*(-Y[i][0]+3.0)/6.0,
2,2); //plotting input data points
getch();
cleardevice();
}
Forward Interpolation C

More Related Content

What's hot

Computer graphics programs in c++
Computer graphics programs in c++Computer graphics programs in c++
Computer graphics programs in c++Ankit Kumar
 
2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graphkinan keshkeh
 
computer graphics practicals
computer graphics practicalscomputer graphics practicals
computer graphics practicalsManoj Chauhan
 
2 5 2-6 absolute value graphs and translations
2 5 2-6 absolute value graphs and translations2 5 2-6 absolute value graphs and translations
2 5 2-6 absolute value graphs and translationsdswanstromecasd
 
Alg 2 : multiply ing & factoring
Alg 2 : multiply ing & factoringAlg 2 : multiply ing & factoring
Alg 2 : multiply ing & factoringpaksukur
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manualUma mohan
 
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : NotesCUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : NotesSubhajit Sahu
 
Numerical Method Assignment
Numerical Method AssignmentNumerical Method Assignment
Numerical Method Assignmentashikul akash
 
Digital Differential Analyzer Line Drawing Algorithm in C
Digital Differential Analyzer Line Drawing Algorithm in CDigital Differential Analyzer Line Drawing Algorithm in C
Digital Differential Analyzer Line Drawing Algorithm in CKasun Ranga Wijeweera
 
Assignement c++
Assignement c++Assignement c++
Assignement c++Syed Umair
 
Создание картограмм на принципах грамматики графики. С помощью R-расширения g...
Создание картограмм на принципах грамматики графики. С помощью R-расширения g...Создание картограмм на принципах грамматики графики. С помощью R-расширения g...
Создание картограмм на принципах грамматики графики. С помощью R-расширения g...Matrunich Consulting
 
Computer graphics lab assignment
Computer graphics lab assignmentComputer graphics lab assignment
Computer graphics lab assignmentAbdullah Al Shiam
 

What's hot (19)

Computer graphics programs in c++
Computer graphics programs in c++Computer graphics programs in c++
Computer graphics programs in c++
 
Julia Set
Julia SetJulia Set
Julia Set
 
2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph
 
Vcs22
Vcs22Vcs22
Vcs22
 
computer graphics practicals
computer graphics practicalscomputer graphics practicals
computer graphics practicals
 
2 5 2-6 absolute value graphs and translations
2 5 2-6 absolute value graphs and translations2 5 2-6 absolute value graphs and translations
2 5 2-6 absolute value graphs and translations
 
Alg 2 : multiply ing & factoring
Alg 2 : multiply ing & factoringAlg 2 : multiply ing & factoring
Alg 2 : multiply ing & factoring
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
 
PythonArtCode
PythonArtCodePythonArtCode
PythonArtCode
 
Sheet 3
Sheet 3Sheet 3
Sheet 3
 
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : NotesCUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
 
Numerical Method Assignment
Numerical Method AssignmentNumerical Method Assignment
Numerical Method Assignment
 
Digital Differential Analyzer Line Drawing Algorithm in C
Digital Differential Analyzer Line Drawing Algorithm in CDigital Differential Analyzer Line Drawing Algorithm in C
Digital Differential Analyzer Line Drawing Algorithm in C
 
Assignement c++
Assignement c++Assignement c++
Assignement c++
 
Langrange method for MATLAB Code
Langrange method for MATLAB CodeLangrange method for MATLAB Code
Langrange method for MATLAB Code
 
Computer graphics
Computer graphics   Computer graphics
Computer graphics
 
Создание картограмм на принципах грамматики графики. С помощью R-расширения g...
Создание картограмм на принципах грамматики графики. С помощью R-расширения g...Создание картограмм на принципах грамматики графики. С помощью R-расширения g...
Создание картограмм на принципах грамматики графики. С помощью R-расширения g...
 
ML
MLML
ML
 
Computer graphics lab assignment
Computer graphics lab assignmentComputer graphics lab assignment
Computer graphics lab assignment
 

Viewers also liked

Fractal extra
Fractal extraFractal extra
Fractal extrarpiitcbme
 
Diffraction cover
Diffraction coverDiffraction cover
Diffraction coverrpiitcbme
 
Monte carlo pi
Monte carlo piMonte carlo pi
Monte carlo pirpiitcbme
 
Diffraction report-3-2015-mac (3)
Diffraction report-3-2015-mac (3)Diffraction report-3-2015-mac (3)
Diffraction report-3-2015-mac (3)rpiitcbme
 
Fractal proj report 2
Fractal proj report 2Fractal proj report 2
Fractal proj report 2rpiitcbme
 
Cover cs project
Cover cs projectCover cs project
Cover cs projectrpiitcbme
 

Viewers also liked (6)

Fractal extra
Fractal extraFractal extra
Fractal extra
 
Diffraction cover
Diffraction coverDiffraction cover
Diffraction cover
 
Monte carlo pi
Monte carlo piMonte carlo pi
Monte carlo pi
 
Diffraction report-3-2015-mac (3)
Diffraction report-3-2015-mac (3)Diffraction report-3-2015-mac (3)
Diffraction report-3-2015-mac (3)
 
Fractal proj report 2
Fractal proj report 2Fractal proj report 2
Fractal proj report 2
 
Cover cs project
Cover cs projectCover cs project
Cover cs project
 

Similar to Forward Interpolation C

Computer Aided Manufacturing Design
Computer Aided Manufacturing DesignComputer Aided Manufacturing Design
Computer Aided Manufacturing DesignV Tripathi
 
Matlab assignment
Matlab assignmentMatlab assignment
Matlab assignmentRutvik
 
Open GL T0074 56 sm4
Open GL T0074 56 sm4Open GL T0074 56 sm4
Open GL T0074 56 sm4Roziq Bahtiar
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxhappycocoman
 
Assignment on Numerical Method C Code
Assignment on Numerical Method C CodeAssignment on Numerical Method C Code
Assignment on Numerical Method C CodeSyed Ahmed Zaki
 
Cg my own programs
Cg my own programsCg my own programs
Cg my own programsAmit Kapoor
 
include.docx
include.docxinclude.docx
include.docxNhiPtaa
 
Gentle Introduction to Functional Programming
Gentle Introduction to Functional ProgrammingGentle Introduction to Functional Programming
Gentle Introduction to Functional ProgrammingSaurabh Singh
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptkinan keshkeh
 
Computer graphics File for Engineers
Computer graphics File for EngineersComputer graphics File for Engineers
Computer graphics File for Engineersvarun arora
 
R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...
R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...
R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...Revolution Analytics
 
package Assignment;import java.util.;public class assignment .pdf
package Assignment;import java.util.;public class assignment .pdfpackage Assignment;import java.util.;public class assignment .pdf
package Assignment;import java.util.;public class assignment .pdfnoelbuddy
 
Forward & Backward Differenece Table
Forward & Backward Differenece TableForward & Backward Differenece Table
Forward & Backward Differenece TableSaloni Singhal
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptkinan keshkeh
 

Similar to Forward Interpolation C (20)

Cs580
Cs580Cs580
Cs580
 
Computer Aided Manufacturing Design
Computer Aided Manufacturing DesignComputer Aided Manufacturing Design
Computer Aided Manufacturing Design
 
Matlab assignment
Matlab assignmentMatlab assignment
Matlab assignment
 
Open GL T0074 56 sm4
Open GL T0074 56 sm4Open GL T0074 56 sm4
Open GL T0074 56 sm4
 
C++ TUTORIAL 10
C++ TUTORIAL 10C++ TUTORIAL 10
C++ TUTORIAL 10
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptx
 
Assignment on Numerical Method C Code
Assignment on Numerical Method C CodeAssignment on Numerical Method C Code
Assignment on Numerical Method C Code
 
Cg my own programs
Cg my own programsCg my own programs
Cg my own programs
 
C++ TUTORIAL 9
C++ TUTORIAL 9C++ TUTORIAL 9
C++ TUTORIAL 9
 
Computer graphics
Computer graphics   Computer graphics
Computer graphics
 
include.docx
include.docxinclude.docx
include.docx
 
No3
No3No3
No3
 
Gentle Introduction to Functional Programming
Gentle Introduction to Functional ProgrammingGentle Introduction to Functional Programming
Gentle Introduction to Functional Programming
 
Los dskn
Los dsknLos dskn
Los dskn
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop concept
 
Computer graphics File for Engineers
Computer graphics File for EngineersComputer graphics File for Engineers
Computer graphics File for Engineers
 
R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...
R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...
R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...
 
package Assignment;import java.util.;public class assignment .pdf
package Assignment;import java.util.;public class assignment .pdfpackage Assignment;import java.util.;public class assignment .pdf
package Assignment;import java.util.;public class assignment .pdf
 
Forward & Backward Differenece Table
Forward & Backward Differenece TableForward & Backward Differenece Table
Forward & Backward Differenece Table
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop concept
 

Recently uploaded

SOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptxSOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptxkessiyaTpeter
 
Temporomandibular joint Muscles of Mastication
Temporomandibular joint Muscles of MasticationTemporomandibular joint Muscles of Mastication
Temporomandibular joint Muscles of Masticationvidulajaib
 
Spermiogenesis or Spermateleosis or metamorphosis of spermatid
Spermiogenesis or Spermateleosis or metamorphosis of spermatidSpermiogenesis or Spermateleosis or metamorphosis of spermatid
Spermiogenesis or Spermateleosis or metamorphosis of spermatidSarthak Sekhar Mondal
 
Transposable elements in prokaryotes.ppt
Transposable elements in prokaryotes.pptTransposable elements in prokaryotes.ppt
Transposable elements in prokaryotes.pptArshadWarsi13
 
insect anatomy and insect body wall and their physiology
insect anatomy and insect body wall and their  physiologyinsect anatomy and insect body wall and their  physiology
insect anatomy and insect body wall and their physiologyDrAnita Sharma
 
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.aasikanpl
 
Is RISC-V ready for HPC workload? Maybe?
Is RISC-V ready for HPC workload? Maybe?Is RISC-V ready for HPC workload? Maybe?
Is RISC-V ready for HPC workload? Maybe?Patrick Diehl
 
Call Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCR
Call Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCRCall Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCR
Call Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCRlizamodels9
 
Forest laws, Indian forest laws, why they are important
Forest laws, Indian forest laws, why they are importantForest laws, Indian forest laws, why they are important
Forest laws, Indian forest laws, why they are importantadityabhardwaj282
 
zoogeography of pakistan.pptx fauna of Pakistan
zoogeography of pakistan.pptx fauna of Pakistanzoogeography of pakistan.pptx fauna of Pakistan
zoogeography of pakistan.pptx fauna of Pakistanzohaibmir069
 
Heredity: Inheritance and Variation of Traits
Heredity: Inheritance and Variation of TraitsHeredity: Inheritance and Variation of Traits
Heredity: Inheritance and Variation of TraitsCharlene Llagas
 
Neurodevelopmental disorders according to the dsm 5 tr
Neurodevelopmental disorders according to the dsm 5 trNeurodevelopmental disorders according to the dsm 5 tr
Neurodevelopmental disorders according to the dsm 5 trssuser06f238
 
‏‏VIRUS - 123455555555555555555555555555555555555555
‏‏VIRUS -  123455555555555555555555555555555555555555‏‏VIRUS -  123455555555555555555555555555555555555555
‏‏VIRUS - 123455555555555555555555555555555555555555kikilily0909
 
Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...Nistarini College, Purulia (W.B) India
 
Artificial Intelligence In Microbiology by Dr. Prince C P
Artificial Intelligence In Microbiology by Dr. Prince C PArtificial Intelligence In Microbiology by Dr. Prince C P
Artificial Intelligence In Microbiology by Dr. Prince C PPRINCE C P
 
Analytical Profile of Coleus Forskohlii | Forskolin .pptx
Analytical Profile of Coleus Forskohlii | Forskolin .pptxAnalytical Profile of Coleus Forskohlii | Forskolin .pptx
Analytical Profile of Coleus Forskohlii | Forskolin .pptxSwapnil Therkar
 
Dashanga agada a formulation of Agada tantra dealt in 3 Rd year bams agada tanta
Dashanga agada a formulation of Agada tantra dealt in 3 Rd year bams agada tantaDashanga agada a formulation of Agada tantra dealt in 3 Rd year bams agada tanta
Dashanga agada a formulation of Agada tantra dealt in 3 Rd year bams agada tantaPraksha3
 
Harmful and Useful Microorganisms Presentation
Harmful and Useful Microorganisms PresentationHarmful and Useful Microorganisms Presentation
Harmful and Useful Microorganisms Presentationtahreemzahra82
 

Recently uploaded (20)

SOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptxSOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
 
Temporomandibular joint Muscles of Mastication
Temporomandibular joint Muscles of MasticationTemporomandibular joint Muscles of Mastication
Temporomandibular joint Muscles of Mastication
 
Spermiogenesis or Spermateleosis or metamorphosis of spermatid
Spermiogenesis or Spermateleosis or metamorphosis of spermatidSpermiogenesis or Spermateleosis or metamorphosis of spermatid
Spermiogenesis or Spermateleosis or metamorphosis of spermatid
 
Transposable elements in prokaryotes.ppt
Transposable elements in prokaryotes.pptTransposable elements in prokaryotes.ppt
Transposable elements in prokaryotes.ppt
 
insect anatomy and insect body wall and their physiology
insect anatomy and insect body wall and their  physiologyinsect anatomy and insect body wall and their  physiology
insect anatomy and insect body wall and their physiology
 
Volatile Oils Pharmacognosy And Phytochemistry -I
Volatile Oils Pharmacognosy And Phytochemistry -IVolatile Oils Pharmacognosy And Phytochemistry -I
Volatile Oils Pharmacognosy And Phytochemistry -I
 
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
 
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
 
Is RISC-V ready for HPC workload? Maybe?
Is RISC-V ready for HPC workload? Maybe?Is RISC-V ready for HPC workload? Maybe?
Is RISC-V ready for HPC workload? Maybe?
 
Call Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCR
Call Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCRCall Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCR
Call Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCR
 
Forest laws, Indian forest laws, why they are important
Forest laws, Indian forest laws, why they are importantForest laws, Indian forest laws, why they are important
Forest laws, Indian forest laws, why they are important
 
zoogeography of pakistan.pptx fauna of Pakistan
zoogeography of pakistan.pptx fauna of Pakistanzoogeography of pakistan.pptx fauna of Pakistan
zoogeography of pakistan.pptx fauna of Pakistan
 
Heredity: Inheritance and Variation of Traits
Heredity: Inheritance and Variation of TraitsHeredity: Inheritance and Variation of Traits
Heredity: Inheritance and Variation of Traits
 
Neurodevelopmental disorders according to the dsm 5 tr
Neurodevelopmental disorders according to the dsm 5 trNeurodevelopmental disorders according to the dsm 5 tr
Neurodevelopmental disorders according to the dsm 5 tr
 
‏‏VIRUS - 123455555555555555555555555555555555555555
‏‏VIRUS -  123455555555555555555555555555555555555555‏‏VIRUS -  123455555555555555555555555555555555555555
‏‏VIRUS - 123455555555555555555555555555555555555555
 
Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...
 
Artificial Intelligence In Microbiology by Dr. Prince C P
Artificial Intelligence In Microbiology by Dr. Prince C PArtificial Intelligence In Microbiology by Dr. Prince C P
Artificial Intelligence In Microbiology by Dr. Prince C P
 
Analytical Profile of Coleus Forskohlii | Forskolin .pptx
Analytical Profile of Coleus Forskohlii | Forskolin .pptxAnalytical Profile of Coleus Forskohlii | Forskolin .pptx
Analytical Profile of Coleus Forskohlii | Forskolin .pptx
 
Dashanga agada a formulation of Agada tantra dealt in 3 Rd year bams agada tanta
Dashanga agada a formulation of Agada tantra dealt in 3 Rd year bams agada tantaDashanga agada a formulation of Agada tantra dealt in 3 Rd year bams agada tanta
Dashanga agada a formulation of Agada tantra dealt in 3 Rd year bams agada tanta
 
Harmful and Useful Microorganisms Presentation
Harmful and Useful Microorganisms PresentationHarmful and Useful Microorganisms Presentation
Harmful and Useful Microorganisms Presentation
 

Forward Interpolation C

  • 1. #include<iostream.h> #include<conio.h> #include<graphics.h> #include<math.h> #define pi 3.1415926 const int n = 5; //number of input data points double sum1 = 0, sum2 = 0, coeff = 1, p, X1, X2; int h; int factorial(int n) { int x=1; while(n>=1) { x=x*n; n--; } return x; } void forward_diff_table(double Y[][n]) { int i, j; for(j=1; j<n; j++) //compute values in the table { for(i=0; i<n-j; i++) { Y[i][j] = Y[i+1][j-1] - Y[i][j-1]; } } } double forward_interpolation(double Y[][n]) { double sum = 0; for(int i=1; i<n; i++) { coeff = 1; for(int j=1; j<=i; j++) { coeff = coeff*(p + 1 - j); } sum = sum + (coeff*Y[0][i])/factorial(i); //sum gives the interpolated value at a given point } return sum; } void main() { clrscr(); double x[n]={10, 20, 30, 40, 50}; //x: input values in degrees double Y[n][n]={{0.1736},{0.342},{0.5},{0.6428},{0.766}}; //Y stores output values corresponding to the input AS WELL AS the difference table
  • 2. h = x[1] - x[0]; //step size forward_diff_table(Y); int gdriver = DETECT, gmode; initgraph(&gdriver, &gmode, "C:turboc3bgi"); //initialising graphics int max_x, max_y; //max_x = 639, max_y = 479 max_x = getmaxx(); max_y = getmaxy(); setcolor(15); //white colour line(max_x/2,0 , max_x/2,max_y); //y axis line(0,max_y/2 , max_x,max_y/2); //x axis //plotting interpolating polynomial setcolor(4); //red colour setlinestyle(0,0,3); int comp_y1, comp_y2; for(int comp_x=0; comp_x<=max_x; comp_x++) { X1 = (comp_x - max_x/2.0)*360.0/(max_x/2.0); //cartesian x (coordinate transformation from computer to cartesian) p = (X1 - x[0])/h; sum1 = forward_interpolation(Y) + Y[0][0]; //cartesian y comp_y1 = max_y * (-sum1 + 3.0)/6.0; //computer y (coordinate transformation from cartesian to computer) X2 = (comp_x + 1 -max_x/2.0)*360.0/(max_x/2.0); p = (X2 - x[0])/h; sum2 = forward_interpolation(Y) + Y[0][0]; comp_y2 = max_y * (-sum2 + 3.0)/6.0; line(comp_x,comp_y1 , comp_x+1,comp_y2); //drawing line between two very very close points } //y = sinx setcolor(14); //yellow colour int X, y1, y2; //computer coordinates double cartesian_x1, cartesian_y1, cartesian_x2, cartesian_y2; //cartesian coordinates for(X=0; X<=max_x; X++) { cartesian_x1 = (X - max_x/2.0)*(2*pi)/(max_x/2.0); //coordinate transformations (X,y1,y2: computer coordinates) cartesian_y1 = sin(cartesian_x1); //f(x) = sinx y1 = max_y*(-cartesian_y1 + 3.0)/6.0; //coordinate transformations cartesian_x2 = (X + 1 - max_x/2.0)*(2*pi)/(max_x/2.0);
  • 3. cartesian_y2 = sin(cartesian_x2); y2 = max_y*(-cartesian_y2 + 3.0)/6.0; line(X,y1, X+1,y2); //draw line b/w (x,sinx) & (x+1,sin(x+1)) } setlinestyle(0,0,1); setcolor(15); line(500,30 , 520,30); outtextxy(530,25, "axes"); setlinestyle(0,0,3); setcolor(14); line(500,60 , 520,60); outtextxy(530,55, "y = sinx"); setcolor(4); line(500,90 , 520,90); outtextxy(530,85, "interpolating"); outtextxy(530,95, "polynomial"); setcolor(1); fillellipse(502,120,2,2); outtextxy(520,115, "input data"); outtextxy(520,125, "points"); setcolor(1); for(int i=0; i<5; i++) fillellipse(max_x*(x[i]+360)/(2.0*360), max_y*(-Y[i][0]+3.0)/6.0, 2,2); //plotting input data points getch(); cleardevice(); }