Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
10
Добавлен:
17.04.2015
Размер:
15.42 Кб
Скачать

//Интерполяция с помощью полинома первой степени (прямой линии)

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

void LIp1c(float x1, float y1,float x2,float y2,int n,float x[], float y[]);

int main()

{

float x1,y1,x2,y2,a,b;

int n;

printf("Vvesti Koordinaty tothek X1 Y1 X2 Y2 n \n");

scanf("%f%f%f%f%i", &x1,&y1,&x2,&y2,&n);

float x[n],y[n];

LIp1c(x1,y1,x2,y2,n,x,y);

printf("\n________________________________");

printf("\n x y ");

printf("\n________________________________");

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

printf("\n %f %f",x[i],y[i]);

printf("\n_______________________________");

system("pause");

return 0;

}

void LIp1c(float x1, float y1,float x2,float y2,int n,float x[], float y[])

{ float a,b,h;

a=(y2-y1)/(x2-x1);

b=y1-a*x1;

h=(x2-x1)/n;

x[0]=x1;

x[n]=x2;

y[0]=y1;

y[n]=y2;

for(int i=1; i<n;i++)

{x[i]=x1+h*i;

y[i]=a*x[i]+b;

}

}

//1 5 2 7 10

// _____________________________

// x y

// _____________________________

// 1.0 5.0

// 1.1 5.2

// 1.2 5.4

// 1.3 5.6

// 1.4 5.8

// 1.5 6.0

// 1.6 6.2

// 1.7 6.4

// 1.8 6.6

// 1.9 6.8

// 2.0 7.0

//_______________________________

//Интерполяция с помощью полинома Ньютона первой степени

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

void LIp1c(float x1, float y1,float x2,float y2,int n,float x[], float y[]);

int main()

{

float x1,y1,x2,y2,a,b;

int n;

printf("Vvesti Koordinaty tothek X1 Y1 X2 Y2 n \n");

scanf("%f%f%f%f%i", &x1,&y1,&x2,&y2,&n);

float x[n],y[n];

LIp1c(x1,y1,x2,y2,n,x,y);

printf("\n________________________________");

printf("\n x y ");

printf("\n________________________________");

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

printf("\n %f %f",x[i],y[i]);

printf("\n_______________________________");

system("pause");

return 0;

}

void LIp1c(float x1, float y1,float x2,float y2,int n,float x[], float y[])

{ float a,b,h;

a=(y2-y1)/(x2-x1);

b=y1-a*x1;

h=(x2-x1)/n;

x[0]=x1;

x[n]=x2;

y[0]=y1;

y[n]=y2;

for(int i=1; i<n;i++)

{x[i]=x1+h*i;

y[i]=y1+(y2-y1)/(x2-x1)*(x[i]-x1);

}

}

//1 5 2 7

// _____________________________

// x y

// _____________________________

// 1.0 5.0

// 1.1 5.2

// 1.2 5.4

// 1.3 5.6

// 1.4 5.8

// 1.5 6.0

// 1.6 6.2

// 1.7 6.4

// 1.8 6.6

// 1.9 6.8

// 2.0 7.0

//_______________________________

//Интерполяция с помощью полинома Лагранжа первой степени

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

void LIp1c(float x1, float y1,float x2,float y2,int n,float x[], float y[]);

int main()

{

float x1,y1,x2,y2,a,b;

int n;

printf("Vvesti Koordinaty tothek X1 Y1 X2 Y2 n \n");

scanf("%f%f%f%f%i", &x1,&y1,&x2,&y2,&n);

float x[n],y[n];

LIp1c(x1,y1,x2,y2,n,x,y);

printf("\n________________________________");

printf("\n x y ");

printf("\n________________________________");

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

printf("\n %f %f",x[i],y[i]);

printf("\n_______________________________");

system("pause");

return 0;

}

void LIp1c(float x1, float y1,float x2,float y2,int n,float x[], float y[])

{ float h;

h=(x2-x1)/n;

x[0]=x1;

x[n]=x2;

y[0]=y1;

y[n]=y2;

for(int i=1; i<n;i++)

{x[i]=x1+h*i;

y[i]=(x[i]-x2)/(x1-x2)*y1+(x[i]-x1)/(x2-x1)*y2;

}

}

//1 5 2 7

// _____________________________

// x y

// _____________________________

// 1.0 5.0

// 1.1 5.2

// 1.2 5.4

// 1.3 5.6

// 1.4 5.8

// 1.5 6.0

// 1.6 6.2

// 1.7 6.4

// 1.8 6.6

// 1.9 6.8

// 2.0 7.0

//_______________________________