1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
#include "header.hpp"
double Basepol(int i,double tau,vector<double>t)
{
double L=1.;
for(int k=0;k<t.size();k++)
{
if(k!=i)
{
L=L*double(tau-t[k])/double(t[i]-t[k]);
}
}
return L;
}
vector<double> Stuetz(int n,double t1, double t2)
{double h=(t2-t1)/n;
vector<double>tau;
for (int i=0;i<=n;i++)
{
tau.push_back(t1+i*h);
}
return tau;
}
double valu(double tau,vector<double>t,vector<double>z)
{
double zeta=0;
for(int i=0;i<z.size();i++)
{
zeta+=z[i]*Basepol(i,tau,t);
}
return zeta;
}
vector<double> Nulst(double eps,double t0,vector<double>t,vector<double>z,vector<double>x)
{
double t1=0,tm=0,te=0;
vector<double>erg(3,0);
while(1)
{
int j=1;
double tmp;
tmp=valu(t0+j,t,z);
if(tmp<0)
{
t1=t0+j;
break;
}
j++;
}
tm=(t0+t1)/2;
while(1)
{
double q;
q=valu(tm,t,z);
if((t1-t0)<eps)break;
if(q<0)t1=tm;
if(q>0)t0=tm;
tm=(t0+t1)/2;
}
te=(t0+t1)/2;
erg[0]=te; erg[1]=valu(te,t,z); erg[2]=valu(te,t,x);
return erg;
}
|