목차
없음
본문내용
in(){
int i, N = 10;
float t;
float w[11];
w[0] = 0;
for(i=0 ; i
t = h*i +1;
w[i+1] = w[i]+ h*Taylor4(w[i],t);
}
for(i=0 ; i<=N ; i++){
t = 1 + h*i;
printf("w(%1.1f) = %f y(%1.1f) = %f error = %f\n",t,w[i], t, y(t), y(t)-w[i]);
}
}
float Taylor4(float w, float t){
return 2*w/t+t*t*exp(t)+h/2*(2*w/t/t+exp(t)*(4*t+t*t))
+h*h/6*(exp(t)*(6+6*t+t*t)+2*w/t/t/t)
+h*h*h/24*(exp(t)*(t*t+8*t+12+2/t)-2*w/t/t/t/t);
}
float y(float t){
return t*t*(exp(t)-exp(1));
}
Result
f.
/* Linear interpolation using Lagrange Polynomial
y' = (2y/t)+t^2*e^2 , for 1<=t<=2 with y(1)=0 and h=0.1
Compare with actual solution and get the error.
*/
#include
#include
float Taylor4(float w, float t);
float y(float t);
float h = 0.1;
main(){
int i, N = 10;
float t, y1, y2, y3;
float w[11];
w[0] = 0;
for(i=0 ; i
t = h*i +1;
w[i+1] = w[i]+ h*Taylor4(w[i],t);
}
y1 = (1.04-1.1)/(1.0-1.1)*w[0]+(1.04-1.0)/(1.1-1.0)*w[1];
printf("w(1.04) = %f y(1.04) = %f error = %f\n",y1,y(1.04),y1-y(1.04));
y2 = (1.55-1.6)/(1.5-1.6)*w[5]+(1.55-1.5)/(1.6-1.5)*w[6];
printf("w(1.55) = %f y(1.55) = %f error = %f\n",y2,y(1.55),y2-y(1.55));
y3 = (1.97-2.0)/(1.9-2.0)*w[9]+(1.97-1.9)/(2.0-1.9)*w[10];
printf("w(1.97) = %f y(1.97) = %f error = %f\n",y3,y(1.97),y3-y(1.97));
}
float Taylor4(float w, float t){
return 2*w/t+t*t*exp(t)+h/2*(2*w/t/t+exp(t)*(4*t+t*t))
+h*h/6*(exp(t)*(6+6*t+t*t)+2*w/t/t/t)
+h*h*h/24*(exp(t)*(t*t+8*t+12+2/t)-2*w/t/t/t/t);
}
float y(float t){
return t*t*(exp(t)-exp(1));
}
Result
int i, N = 10;
float t;
float w[11];
w[0] = 0;
for(i=0 ; i
w[i+1] = w[i]+ h*Taylor4(w[i],t);
}
for(i=0 ; i<=N ; i++){
t = 1 + h*i;
printf("w(%1.1f) = %f y(%1.1f) = %f error = %f\n",t,w[i], t, y(t), y(t)-w[i]);
}
}
float Taylor4(float w, float t){
return 2*w/t+t*t*exp(t)+h/2*(2*w/t/t+exp(t)*(4*t+t*t))
+h*h/6*(exp(t)*(6+6*t+t*t)+2*w/t/t/t)
+h*h*h/24*(exp(t)*(t*t+8*t+12+2/t)-2*w/t/t/t/t);
}
float y(float t){
return t*t*(exp(t)-exp(1));
}
Result
f.
/* Linear interpolation using Lagrange Polynomial
y' = (2y/t)+t^2*e^2 , for 1<=t<=2 with y(1)=0 and h=0.1
Compare with actual solution and get the error.
*/
#include
#include
float Taylor4(float w, float t);
float y(float t);
float h = 0.1;
main(){
int i, N = 10;
float t, y1, y2, y3;
float w[11];
w[0] = 0;
for(i=0 ; i
w[i+1] = w[i]+ h*Taylor4(w[i],t);
}
y1 = (1.04-1.1)/(1.0-1.1)*w[0]+(1.04-1.0)/(1.1-1.0)*w[1];
printf("w(1.04) = %f y(1.04) = %f error = %f\n",y1,y(1.04),y1-y(1.04));
y2 = (1.55-1.6)/(1.5-1.6)*w[5]+(1.55-1.5)/(1.6-1.5)*w[6];
printf("w(1.55) = %f y(1.55) = %f error = %f\n",y2,y(1.55),y2-y(1.55));
y3 = (1.97-2.0)/(1.9-2.0)*w[9]+(1.97-1.9)/(2.0-1.9)*w[10];
printf("w(1.97) = %f y(1.97) = %f error = %f\n",y3,y(1.97),y3-y(1.97));
}
float Taylor4(float w, float t){
return 2*w/t+t*t*exp(t)+h/2*(2*w/t/t+exp(t)*(4*t+t*t))
+h*h/6*(exp(t)*(6+6*t+t*t)+2*w/t/t/t)
+h*h*h/24*(exp(t)*(t*t+8*t+12+2/t)-2*w/t/t/t/t);
}
float y(float t){
return t*t*(exp(t)-exp(1));
}
Result
소개글