|
#include <iostream.h>
void main (void)
{
cout<< "三次関数製造機によるグラフの補間です。\n";
cout<< "x1の値は?";
long double x1, x2, x3, x4;
long double y1, y2, y3, y4;
cin>> x1;
cout<<"y1の値は?";
cin>> y1;
cout<<"x2の値は?";
cin>> x2;
cout<<"y2の値は?";
cin>> y2;
cout<<"x3の値は?";
cin>> x3;
cout<<"y3の値は?";
cin>> y3;
cout<<"x4の値は?";
cin>> x4;
cout<<"y4の値は?";
cin>> y4;
long double ay1 = y1;
long double ay2 = y2;
long double ay3 = y3;
long double ay4 = y4;
long double a, b, c, d;
long double ty1, ty2, ty3, ty4;
do{
c = (ay2-ay1)/(x2-x1);
d = ay1-c*x1;
b = (ay3-(c*x3+d))/pow(x3,2);
a = (ay4-(b*pow(x4,2)+c*x4+d))/pow(x4,3);
ty1 = a*pow(x1,3)+b*pow(x1,2)+c*x1+d;
ty2 = a*pow(x2,3)+b*pow(x2,2)+c*x2+d;
ty3 = a*pow(x3,3)+b*pow(x3,2)+c*x3+d;
ty4 = a*pow(x4,3)+b*pow(x4,2)+c*x4+d;
ay1 = (y1/ty1)*ay1;
ay2 = (y2/ty2)*ay2;
ay3 = (y3/ty3)*ay3;
ay4 = (y4/ty4)*ay4;
}while( y1 != ty1 && y2 != ty2 && y3 !=ty3);
cout<<"y=";
cout.precision(20);
cout<< a;
cout<<"x^3+";
cout<< b;
cout<<"x^2+";
cout<< c;
cout<<"x+";
cout<< d;
int i ;
do{
cout<<"\n求めたいxの値を入力してください。\n";
long double x;
cin>> x;
long double y = a*pow(x,3)+b*pow(x,2)+c*x+d;
cout<< y;
cout<<"計算を続けるなら1、\nやめるなら1以外の数を入力してください。";
cin>>i;
}while(i==1);
}
|
|