SlideShare a Scribd company logo
#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();
}
Interpolation graph 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
 
Julia Set
Julia SetJulia Set
Julia Set
Ashish Kumar
 
2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph
kinan keshkeh
 
computer graphics practicals
computer graphics practicalscomputer graphics practicals
computer graphics practicals
Manoj 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 manual
Uma mohan
 
Sheet 3
Sheet 3Sheet 3
Sheet 3
Ahmed Elmorsy
 
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
Subhajit Sahu
 
Numerical Method Assignment
Numerical Method AssignmentNumerical Method Assignment
Numerical Method Assignment
ashikul 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 C
Kasun Ranga Wijeweera
 
Assignement c++
Assignement c++Assignement c++
Assignement c++
Syed Umair
 
Langrange method for MATLAB Code
Langrange method for MATLAB CodeLangrange method for MATLAB Code
Langrange method for MATLAB Code
Taimoor Muzaffar Gondal
 
Computer graphics
Computer graphics   Computer graphics
Computer graphics
Prianka Padmanaban
 
Создание картограмм на принципах грамматики графики. С помощью R-расширения g...
Создание картограмм на принципах грамматики графики. С помощью R-расширения g...Создание картограмм на принципах грамматики графики. С помощью R-расширения g...
Создание картограмм на принципах грамматики графики. С помощью R-расширения g...
Matrunich Consulting
 
ML
MLML
Computer graphics lab assignment
Computer graphics lab assignmentComputer graphics lab assignment
Computer graphics lab assignment
Abdullah 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 extra
rpiitcbme
 
Diffraction cover
Diffraction coverDiffraction cover
Diffraction cover
rpiitcbme
 
Monte carlo pi
Monte carlo piMonte carlo pi
Monte carlo pi
rpiitcbme
 
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 2
rpiitcbme
 
Cover cs project
Cover cs projectCover cs project
Cover cs project
rpiitcbme
 

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 Interpolation graph c++

Cs580
Cs580Cs580
Computer Aided Manufacturing Design
Computer Aided Manufacturing DesignComputer Aided Manufacturing Design
Computer Aided Manufacturing Design
V Tripathi
 
Matlab assignment
Matlab assignmentMatlab assignment
Matlab assignment
Rutvik
 
Open GL T0074 56 sm4
Open GL T0074 56 sm4Open GL T0074 56 sm4
Open GL T0074 56 sm4Roziq Bahtiar
 
C++ TUTORIAL 10
C++ TUTORIAL 10C++ TUTORIAL 10
C++ TUTORIAL 10
Farhan Ab Rahman
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptx
happycocoman
 
Assignment on Numerical Method C Code
Assignment on Numerical Method C CodeAssignment on Numerical Method C Code
Assignment on Numerical Method C Code
Syed Ahmed Zaki
 
Cg my own programs
Cg my own programsCg my own programs
Cg my own programsAmit Kapoor
 
C++ TUTORIAL 9
C++ TUTORIAL 9C++ TUTORIAL 9
C++ TUTORIAL 9
Farhan Ab Rahman
 
Computer graphics
Computer graphics   Computer graphics
Computer graphics
Prianka Padmanaban
 
include.docx
include.docxinclude.docx
include.docx
NhiPtaa
 
No3
No3No3
Gentle Introduction to Functional Programming
Gentle Introduction to Functional ProgrammingGentle Introduction to Functional Programming
Gentle Introduction to Functional Programming
Saurabh Singh
 
Los dskn
Los dsknLos dskn
Los dskn
Brenda Jazmin
 
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
kinan keshkeh
 
Computer graphics File for Engineers
Computer graphics File for EngineersComputer graphics File for Engineers
Computer graphics File for Engineers
varun 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 .pdf
noelbuddy
 
Forward & Backward Differenece Table
Forward & Backward Differenece TableForward & Backward Differenece Table
Forward & Backward Differenece Table
Saloni 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 concept
kinan keshkeh
 

Similar to Interpolation graph 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

Lab report on liquid viscosity of glycerin
Lab report on liquid viscosity of glycerinLab report on liquid viscosity of glycerin
Lab report on liquid viscosity of glycerin
ossaicprecious19
 
Cancer cell metabolism: special Reference to Lactate Pathway
Cancer cell metabolism: special Reference to Lactate PathwayCancer cell metabolism: special Reference to Lactate Pathway
Cancer cell metabolism: special Reference to Lactate Pathway
AADYARAJPANDEY1
 
THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.
THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.
THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.
Sérgio Sacani
 
Richard's entangled aventures in wonderland
Richard's entangled aventures in wonderlandRichard's entangled aventures in wonderland
Richard's entangled aventures in wonderland
Richard Gill
 
Unveiling the Energy Potential of Marshmallow Deposits.pdf
Unveiling the Energy Potential of Marshmallow Deposits.pdfUnveiling the Energy Potential of Marshmallow Deposits.pdf
Unveiling the Energy Potential of Marshmallow Deposits.pdf
Erdal Coalmaker
 
Seminar of U.V. Spectroscopy by SAMIR PANDA
 Seminar of U.V. Spectroscopy by SAMIR PANDA Seminar of U.V. Spectroscopy by SAMIR PANDA
Seminar of U.V. Spectroscopy by SAMIR PANDA
SAMIR PANDA
 
Nutraceutical market, scope and growth: Herbal drug technology
Nutraceutical market, scope and growth: Herbal drug technologyNutraceutical market, scope and growth: Herbal drug technology
Nutraceutical market, scope and growth: Herbal drug technology
Lokesh Patil
 
Richard's aventures in two entangled wonderlands
Richard's aventures in two entangled wonderlandsRichard's aventures in two entangled wonderlands
Richard's aventures in two entangled wonderlands
Richard Gill
 
GBSN - Biochemistry (Unit 5) Chemistry of Lipids
GBSN - Biochemistry (Unit 5) Chemistry of LipidsGBSN - Biochemistry (Unit 5) Chemistry of Lipids
GBSN - Biochemistry (Unit 5) Chemistry of Lipids
Areesha Ahmad
 
Citrus Greening Disease and its Management
Citrus Greening Disease and its ManagementCitrus Greening Disease and its Management
Citrus Greening Disease and its Management
subedisuryaofficial
 
Earliest Galaxies in the JADES Origins Field: Luminosity Function and Cosmic ...
Earliest Galaxies in the JADES Origins Field: Luminosity Function and Cosmic ...Earliest Galaxies in the JADES Origins Field: Luminosity Function and Cosmic ...
Earliest Galaxies in the JADES Origins Field: Luminosity Function and Cosmic ...
Sérgio Sacani
 
Structural Classification Of Protein (SCOP)
Structural Classification Of Protein  (SCOP)Structural Classification Of Protein  (SCOP)
Structural Classification Of Protein (SCOP)
aishnasrivastava
 
EY - Supply Chain Services 2018_template.pptx
EY - Supply Chain Services 2018_template.pptxEY - Supply Chain Services 2018_template.pptx
EY - Supply Chain Services 2018_template.pptx
AlguinaldoKong
 
(May 29th, 2024) Advancements in Intravital Microscopy- Insights for Preclini...
(May 29th, 2024) Advancements in Intravital Microscopy- Insights for Preclini...(May 29th, 2024) Advancements in Intravital Microscopy- Insights for Preclini...
(May 29th, 2024) Advancements in Intravital Microscopy- Insights for Preclini...
Scintica Instrumentation
 
Astronomy Update- Curiosity’s exploration of Mars _ Local Briefs _ leadertele...
Astronomy Update- Curiosity’s exploration of Mars _ Local Briefs _ leadertele...Astronomy Update- Curiosity’s exploration of Mars _ Local Briefs _ leadertele...
Astronomy Update- Curiosity’s exploration of Mars _ Local Briefs _ leadertele...
NathanBaughman3
 
Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...
Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...
Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...
Ana Luísa Pinho
 
NuGOweek 2024 Ghent - programme - final version
NuGOweek 2024 Ghent - programme - final versionNuGOweek 2024 Ghent - programme - final version
NuGOweek 2024 Ghent - programme - final version
pablovgd
 
insect taxonomy importance systematics and classification
insect taxonomy importance systematics and classificationinsect taxonomy importance systematics and classification
insect taxonomy importance systematics and classification
anitaento25
 
In silico drugs analogue design: novobiocin analogues.pptx
In silico drugs analogue design: novobiocin analogues.pptxIn silico drugs analogue design: novobiocin analogues.pptx
In silico drugs analogue design: novobiocin analogues.pptx
AlaminAfendy1
 
in vitro propagation of plants lecture note.pptx
in vitro propagation of plants lecture note.pptxin vitro propagation of plants lecture note.pptx
in vitro propagation of plants lecture note.pptx
yusufzako14
 

Recently uploaded (20)

Lab report on liquid viscosity of glycerin
Lab report on liquid viscosity of glycerinLab report on liquid viscosity of glycerin
Lab report on liquid viscosity of glycerin
 
Cancer cell metabolism: special Reference to Lactate Pathway
Cancer cell metabolism: special Reference to Lactate PathwayCancer cell metabolism: special Reference to Lactate Pathway
Cancer cell metabolism: special Reference to Lactate Pathway
 
THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.
THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.
THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.
 
Richard's entangled aventures in wonderland
Richard's entangled aventures in wonderlandRichard's entangled aventures in wonderland
Richard's entangled aventures in wonderland
 
Unveiling the Energy Potential of Marshmallow Deposits.pdf
Unveiling the Energy Potential of Marshmallow Deposits.pdfUnveiling the Energy Potential of Marshmallow Deposits.pdf
Unveiling the Energy Potential of Marshmallow Deposits.pdf
 
Seminar of U.V. Spectroscopy by SAMIR PANDA
 Seminar of U.V. Spectroscopy by SAMIR PANDA Seminar of U.V. Spectroscopy by SAMIR PANDA
Seminar of U.V. Spectroscopy by SAMIR PANDA
 
Nutraceutical market, scope and growth: Herbal drug technology
Nutraceutical market, scope and growth: Herbal drug technologyNutraceutical market, scope and growth: Herbal drug technology
Nutraceutical market, scope and growth: Herbal drug technology
 
Richard's aventures in two entangled wonderlands
Richard's aventures in two entangled wonderlandsRichard's aventures in two entangled wonderlands
Richard's aventures in two entangled wonderlands
 
GBSN - Biochemistry (Unit 5) Chemistry of Lipids
GBSN - Biochemistry (Unit 5) Chemistry of LipidsGBSN - Biochemistry (Unit 5) Chemistry of Lipids
GBSN - Biochemistry (Unit 5) Chemistry of Lipids
 
Citrus Greening Disease and its Management
Citrus Greening Disease and its ManagementCitrus Greening Disease and its Management
Citrus Greening Disease and its Management
 
Earliest Galaxies in the JADES Origins Field: Luminosity Function and Cosmic ...
Earliest Galaxies in the JADES Origins Field: Luminosity Function and Cosmic ...Earliest Galaxies in the JADES Origins Field: Luminosity Function and Cosmic ...
Earliest Galaxies in the JADES Origins Field: Luminosity Function and Cosmic ...
 
Structural Classification Of Protein (SCOP)
Structural Classification Of Protein  (SCOP)Structural Classification Of Protein  (SCOP)
Structural Classification Of Protein (SCOP)
 
EY - Supply Chain Services 2018_template.pptx
EY - Supply Chain Services 2018_template.pptxEY - Supply Chain Services 2018_template.pptx
EY - Supply Chain Services 2018_template.pptx
 
(May 29th, 2024) Advancements in Intravital Microscopy- Insights for Preclini...
(May 29th, 2024) Advancements in Intravital Microscopy- Insights for Preclini...(May 29th, 2024) Advancements in Intravital Microscopy- Insights for Preclini...
(May 29th, 2024) Advancements in Intravital Microscopy- Insights for Preclini...
 
Astronomy Update- Curiosity’s exploration of Mars _ Local Briefs _ leadertele...
Astronomy Update- Curiosity’s exploration of Mars _ Local Briefs _ leadertele...Astronomy Update- Curiosity’s exploration of Mars _ Local Briefs _ leadertele...
Astronomy Update- Curiosity’s exploration of Mars _ Local Briefs _ leadertele...
 
Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...
Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...
Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...
 
NuGOweek 2024 Ghent - programme - final version
NuGOweek 2024 Ghent - programme - final versionNuGOweek 2024 Ghent - programme - final version
NuGOweek 2024 Ghent - programme - final version
 
insect taxonomy importance systematics and classification
insect taxonomy importance systematics and classificationinsect taxonomy importance systematics and classification
insect taxonomy importance systematics and classification
 
In silico drugs analogue design: novobiocin analogues.pptx
In silico drugs analogue design: novobiocin analogues.pptxIn silico drugs analogue design: novobiocin analogues.pptx
In silico drugs analogue design: novobiocin analogues.pptx
 
in vitro propagation of plants lecture note.pptx
in vitro propagation of plants lecture note.pptxin vitro propagation of plants lecture note.pptx
in vitro propagation of plants lecture note.pptx
 

Interpolation graph 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(); }