hello, i barely know how to use python and i need to write a cubic spline interpolation code in python for my programming assignment . I have C++ code but i know nothing about c++ so can someone help me to convert that code to python code?
this is a very important and i don't have eneugh time to learn how to do it by myself, so i really need someone's help.
the exmple in the attachement is the same example in the c++ code.
#include<iostream>
#include<cmath>
/*Modele pour la construction des fonction g(x) de cubiquesSpline */
using namespace std;
#define n 5
double S[n+1];
double x[]={1,2,3,4,5,6};
double y[]={1.0,3.1,1.5,2.5,3.4,1.98};
int main()
{
int i;
double a[n+1],b[n+1],c[n+1],d[n+1],h[n+1];
double *ai, *bi,*ci,*di;
double m;
ai=new double[n+2];
bi=new double[n+2];
ci=new double[n+2];
di=new double[n+2];
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
for(int i=0;i<=n;i++)
{
h[i]=x[i+1]-x[i];
}
ai[0]=0;
bi[0]=1.0;
ci[0]=0.0;
di[0]=0.0;
ai[n]=0;
bi[n]=1.0;
ci[n]=0.0;
di[n]=0.0;
cout <<"x[i] \t y[i]"<<endl;
for(int i=0;i<=n;i++)
{
cout << x[i]<<"\t"<<y[i]<<endl;
}
for(int i=1;i<=n-1;i++)
{
ai[i]=h[i-1];
bi[i]=2.0*(h[i]+h[i-1]);
ci[i]=h[i];
di[i]=6.0*((y[i+1]-y[i])/h[i]-(y[i]-y[i-1])/h[i-1]);
}
for(int i=1;i<=n;i++)
{
m=ai[i]/bi[i-1];
bi[i]=bi[i]-m*ci[i-1];
di[i]=di[i]-m*di[i-1];
}
S[n]=di[n]/bi[n];
for(int i=n-1;i>=0;i--)
{
S[i]=(di[i]-ci[i]*S[i+1])/bi[i];
}
cout<<"g(i) \t a[i] \t b[i] \t c[i] \t d[i]"<<endl;
for (i=0;i<=4;i++)
{
a[i]=(S[i+1]-S[i])/6.0;
b[i]=S[i]/2;
c[i]=(y[i+1]-y[i])-(2.0*S[i]+S[i+1])/6.0;
d[i]=y[i];
cout<<i<<"\t"<<a[i]<< "\t"<<b[i]<<"\t"<<c[i]<<"\t"<<d[i]<< endl ;
}
delete [] ai,bi,ci,di;
return 0;
}