diff options
Diffstat (limited to '75/CH4')
-rwxr-xr-x | 75/CH4/EX4.1/ex_12.sce | 8 | ||||
-rwxr-xr-x | 75/CH4/EX4.10/ex_9.sce | 9 | ||||
-rwxr-xr-x | 75/CH4/EX4.11/ex_11.sce | 25 | ||||
-rwxr-xr-x | 75/CH4/EX4.2/ex_1.sce | 60 | ||||
-rwxr-xr-x | 75/CH4/EX4.3/ex_2.sce | 23 | ||||
-rwxr-xr-x | 75/CH4/EX4.4/ex_3.sce | 12 | ||||
-rwxr-xr-x | 75/CH4/EX4.5/ex_5.sce | 9 | ||||
-rwxr-xr-x | 75/CH4/EX4.6/ex_5.sce | 8 | ||||
-rwxr-xr-x | 75/CH4/EX4.7/ex_6.sce | 27 | ||||
-rwxr-xr-x | 75/CH4/EX4.8/ex_7.sce | 28 | ||||
-rwxr-xr-x | 75/CH4/EX4.9/ex_8.sce | 20 |
11 files changed, 229 insertions, 0 deletions
diff --git a/75/CH4/EX4.1/ex_12.sce b/75/CH4/EX4.1/ex_12.sce new file mode 100755 index 000000000..647febdb9 --- /dev/null +++ b/75/CH4/EX4.1/ex_12.sce @@ -0,0 +1,8 @@ + // PG (199) + +x = poly(0,"x"); +p3 = 1 + x + (1/2)*x^(2) + (1/6)*x^3 +deff('[y]=f(x)','y=exp(x)') +funcprot(0) +x = -1:0.01:1; +f(x) - p3 diff --git a/75/CH4/EX4.10/ex_9.sce b/75/CH4/EX4.10/ex_9.sce new file mode 100755 index 000000000..b3ba594e2 --- /dev/null +++ b/75/CH4/EX4.10/ex_9.sce @@ -0,0 +1,9 @@ + // PG (227) + +deff('[y]=f(x)','y=exp(x)') +c3=0.994571+0.997308*x+0.542991*x^2+0.177347*x^3; +norm(exp(x)-c3,'inf') + +// as obtained in the example 6, c4 = 0.00547, T4(x) = (-1) +// c4*T4(x) = 0.00547 * (-1) +// norm(exp(x)-q3,'inf') = 0.00553
\ No newline at end of file diff --git a/75/CH4/EX4.11/ex_11.sce b/75/CH4/EX4.11/ex_11.sce new file mode 100755 index 000000000..2ac7242f1 --- /dev/null +++ b/75/CH4/EX4.11/ex_11.sce @@ -0,0 +1,25 @@ + // PG (234) + +deff('[y]=f(x)','y=exp(x)') +x = -1:0.01:1; +// For +n = 1; +x = [-1 0 1]; +E1 = 0.272; +F1 = 1.2715 + 1.1752*x; + +// Relative errors + +x = -1.0; +exp(x) - F1; +r1 = ans(1,1) +x = 0.1614; +exp(x) - F1; +r2 = ans(1,2) +x = 1.0; +exp(x) - F1; +r3 = ans(1,3) + +F3 = 0.994526 + 0.995682*x + 0.543981*x*x + 0.179519*x*x*x; +x = [-1.0 -0.6832 0.0493 0.7324 1.0] +exp(x) - F3 // relative errors
\ No newline at end of file diff --git a/75/CH4/EX4.2/ex_1.sce b/75/CH4/EX4.2/ex_1.sce new file mode 100755 index 000000000..d0d5ebc5f --- /dev/null +++ b/75/CH4/EX4.2/ex_1.sce @@ -0,0 +1,60 @@ + // PG (200) + +deff('[y]=f(x)','y=exp(x)') + +xset('window',0); +x=-1:.01:1; // defining the range of x. +y=feval(x,f); + +a=gca(); + +a.y_location = "origin"; + +a.x_location = "origin"; +plot(x,y) // instruction to plot the graph + + + +// possible approximation +// y = q1(x) + +// Let e(x) = exp(x) - [a0+a1*x] +// q1(x) & exp(x) must be equal at two points in [-1,1], say at x1 & x2 +// sigma1 = max(abs(e(x))) +// e(x1) = e(x2) = 0. +// By another argument based on shifting the graph of y = q1(x), +// we conclude that the maximum error sigma1 is attained at exactly 3 points. +// e(-1) = sigma1 +// e(1) = sigma1 +// e(x3) = -sigma1 +// x1 < x3 < x2 +// Since e(x) has a relative minimum at x3, we have e'(x) = 0 +// Combining these 4 equations, we have.. +// exp(-1) - [a0-a1] = sigma1 ------------------(i) +// exp(1) - [a0+a1] = p1 -----------------------(ii) +// exp(x3) - [a0+a1*x3] = -sigma1 --------------(iii) +// exp(x3) - a1 = 0 ----------------------------(iv) + +// These have the solution + +a1 = (exp(1) - exp(-1))/2 +x3 = log(a1) +sigma1 = 0.5*exp(-1) + x3*(exp(1) - exp(-1))/4 +a0 = sigma1 + (1-x3)*a1 + +x = poly(0,"x"); +// Thus, +q1 = a0 + a1*x + +deff('[y1]=f(x)','y1=1.2643+1.1752*x') + +xset('window',0); +x=-1:.01:1; // defining the range of x. +y=feval(x,f); + +a=gca(); + +a.y_location = "origin"; + +a.x_location = "origin"; +plot(x,y) // instruction to plot the graph diff --git a/75/CH4/EX4.3/ex_2.sce b/75/CH4/EX4.3/ex_2.sce new file mode 100755 index 000000000..20950fb4b --- /dev/null +++ b/75/CH4/EX4.3/ex_2.sce @@ -0,0 +1,23 @@ + // PG (205) + +deff('[y]=f(x)','y=exp(x)') + +x=-1:.01:1; // defining the range of x + +// Let r1(x) = b0 + b1(x) +// Minimize +// ||f-r1||^2 = integrate('(exp(x)-b0-b1*x)^2','x',-1,1) = F(b0,b1) +// F = integrate('exp(2*x) + b0^2 + (b1^2)*(x^2) - 2*b0*x*exp(x) + 2*b0*b1*x','x',b0,b1) +// To find a minimum, we set + +// df/db0 = 0 +// df/db1 = 0-----------necessary conditions at a minimal point +// On solving, we get the values of b0 & b1 + +b0 = 0.5*integrate('exp(x)','x',-1,1) +b1 = 1.5*integrate('x*exp(x)','x',-1,1) +r1 = b0+b1*x; +norm(exp(x)-r1,'inf') // least squares approximation + +r3 = 0.996294 + 0.997955*x + 0.536722*x^2 + 0.176139*x^3 +norm(exp(x)-r3,'inf') // cubic least squares approximation
\ No newline at end of file diff --git a/75/CH4/EX4.4/ex_3.sce b/75/CH4/EX4.4/ex_3.sce new file mode 100755 index 000000000..59ed524c3 --- /dev/null +++ b/75/CH4/EX4.4/ex_3.sce @@ -0,0 +1,12 @@ + // PG (206) + +// The following are the weight functions of most interest in the +// developments of this text: + +// w(x)=1 a < = x < = b + +// w(x)=1/sqrt(1-x^2) -1 < = x < = 1 + +// w(x)=exp(-x) 0 < = x < infinity + +// w(x)=exp(-x^2) -infinity < x < infinity
\ No newline at end of file diff --git a/75/CH4/EX4.5/ex_5.sce b/75/CH4/EX4.5/ex_5.sce new file mode 100755 index 000000000..a52e70ef8 --- /dev/null +++ b/75/CH4/EX4.5/ex_5.sce @@ -0,0 +1,9 @@ + // PG (215) + +// for laguerre polynomials, +// L(n+1)=1*[2*n+1-x]*L(n)/(n+1) - n*L(n-1)/(n+1) + +// for Legendre polynomials, + +// P(n+1)= (2*n +1)*x*P(n)/(n+1) - n*P(n-1)/(n+1) + diff --git a/75/CH4/EX4.6/ex_5.sce b/75/CH4/EX4.6/ex_5.sce new file mode 100755 index 000000000..61e424105 --- /dev/null +++ b/75/CH4/EX4.6/ex_5.sce @@ -0,0 +1,8 @@ + // PG (215) + +// for laguerre polynomials, +// L(n+1)=1*[2*n+1-x]*L(n)/(n+1) - n*L(n-1)/(n+1) + +// for Legendre polynomials, + +// P(n+1)= (2*n +1)*x*P(n)/(n+1) - n*P(n-1)/(n+1)
\ No newline at end of file diff --git a/75/CH4/EX4.7/ex_6.sce b/75/CH4/EX4.7/ex_6.sce new file mode 100755 index 000000000..b87b04d2a --- /dev/null +++ b/75/CH4/EX4.7/ex_6.sce @@ -0,0 +1,27 @@ + // PG (219) + +deff('[y]=f(x)','y=exp(x)') + +x=-1:.01:1; // defining the range of x + +// Let r1(x) = b0 + b1(x) +// Minimize +// ||f-r1||^2 = integrate('(exp(x)-b0-b1*x)^2','x',-1,1) = F(b0,b1) +// F = integrate('exp(2*x) + b0^2 + (b1^2)*(x^2) - 2*b0*x*exp(x) + 2*b0*b1*x','x',b0,b1) +// To find a minimum, we set + +// df/db0 = 0 +// df/db1 = 0-----------necessary conditions at a minimal point +// On solving, we get the values of b0 & b1 + +b0 = 0.5*integrate('exp(x)','x',-1,1); +b1 = 1.5*integrate('x*exp(x)','x',-1,1); +r1 = b0+b1*x; +norm(exp(x)-r1,'inf'); // least squares approximation + +r3 = 0.996294 + 0.997955*x + 0.536722*x^2 + 0.176139*x^3; +norm(exp(x)-r3,'inf'); // cubic least squares approximation + +// average error E + +E = norm(exp(x)-r3,2)/sqrt(2) diff --git a/75/CH4/EX4.8/ex_7.sce b/75/CH4/EX4.8/ex_7.sce new file mode 100755 index 000000000..01c0b0149 --- /dev/null +++ b/75/CH4/EX4.8/ex_7.sce @@ -0,0 +1,28 @@ + // PG (220) + +deff('[y]=f(x)','y=exp(x)') + +// Chebyshev expansion coefficients for exp(x) +// j = 0 +C0=2*(integrate('exp(cos(x))','x',0,3.14))/(3.14) + +// j = 1 +C1=2*(integrate('exp(cos(x))*cos(x)','x',0,3.14))/(3.14) + +// j = 2 +C2=2*(integrate('exp(cos(x))*cos(2*x)','x',0,3.14))/(3.14) + +// j = 3 +C3=2*(integrate('exp(cos(x))*cos(3*x)','x',0,3.14))/(3.14) + +// j = 4 +C4=2*(integrate('exp(cos(x))*cos(4*x)','x',0,3.14))/(3.14) + +// j = 5 +C5=2*(integrate('exp(cos(x))*cos(5*x)','x',0,3.14))/(3.14) + +// we obtain +c1=1.266+1.130*x; +c3=0.994571+0.997308*x+0.542991*x^2+0.177347*x^3; +norm(exp(x)-c1,'inf') +norm(exp(x)-c3,'inf')
\ No newline at end of file diff --git a/75/CH4/EX4.9/ex_8.sce b/75/CH4/EX4.9/ex_8.sce new file mode 100755 index 000000000..7c502a299 --- /dev/null +++ b/75/CH4/EX4.9/ex_8.sce @@ -0,0 +1,20 @@ + // PG (223) + +deff('[y]=f(x)','y=exp(x)') + +x=[-1.0 -0.6919 0.0310 0.7229 1.0]; // defining x + +r3 = 0.996294 + 0.997955*x + 0.536722*x^2 + 0.176139*x^3; +norm(exp(x)-r3,'inf'); // cubic least squares approximation +deff('[y]=g(x)','y=0.994571+0.997308*x+0.542991*x^2+0.177347*x^3') +// c3=g(x); +x1=x(1,1); +(exp(x1)-g(x1)) +x2=x(1,2); +(exp(x2)-g(x2)) +x3=x(1,3); +(exp(x3)-g(x3)) +x4=x(1,4); +(exp(x4)-g(x4)) +x5=x(1,5); +(exp(x5)-g(x5)) |