From f35ea80659b6a49d1bb2ce1d7d002583f3f40947 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Tue, 10 Oct 2017 12:38:01 +0530 Subject: updated the code --- 191/CH5/EX5.16/Example5_16.sce | 90 +++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 45 deletions(-) (limited to '191/CH5/EX5.16/Example5_16.sce') diff --git a/191/CH5/EX5.16/Example5_16.sce b/191/CH5/EX5.16/Example5_16.sce index a246a8985..1cd2060b7 100755 --- a/191/CH5/EX5.16/Example5_16.sce +++ b/191/CH5/EX5.16/Example5_16.sce @@ -1,45 +1,45 @@ -//Least square approximation to continuous functions -clc; -clear; -close(); -format('v',8); -funcprot(0); -deff('[g]=f(x,y)','g= -y^2/(1+x)'); -disp('approximation of e^x on [0,1] with a uniform weight w(x)=1') -a11 = integrate('1','x',0,1); -a12 = integrate('x','x',0,1); -a13 = integrate('x*x','x',0,1); -a14 = integrate('x^3','x',0,1); -a21 = integrate('x','x',0,1); -a22 = integrate('x^2','x',0,1); -a23 = integrate('x^3','x',0,1); -a24 = integrate('x^4','x',0,1); -a31 = integrate('x^2','x',0,1); -a32 = integrate('x^3','x',0,1); -a33 = integrate('x^4','x',0,1); -a34 = integrate('x^5','x',0,1); -a41 = integrate('x^3','x',0,1); -a42 = integrate('x^4','x',0,1); -a43 = integrate('x^5','x',0,1); -a44 = integrate('x^6','x',0,1); - -c1 = integrate('exp(x)','x',0,1); -c2 = integrate('x*exp(x)','x',0,1); -c3 = integrate('x^2*exp(x)','x',0,1); -c4 = integrate('x^3*exp(x)','x',0,1); - -A = [a11 a12 a13 a14;a21 a22 a23 a24;a31 a32 a33 a34;a41 a42 a43 a44]; -C = [c1;c2;c3;c4]; -ann = inv(A)*C; -disp(ann, 'The coefficients a0,a1,a2,a3 are respectively : ' ); - -deff('[px]=p3(x)','px=ann(4)*x^3+ann(3)*x^2+ann(2)*x+ann(1)'); -x = [0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0]'; -e = exp(x); -p = p3(x); -err = e-p; -ann = [x e p err]; - -disp(ann,'Displaying the value of x exp(x) p3(x) exp(x)-p3(x) :'); -plot(x,err); -plot(x,0); \ No newline at end of file +//Least square approximation to continuous functions +clc; +clear; +close(); +format('v',8); +funcprot(0); +deff('[g]=f(x,y)','g= -y^2/(1+x)'); +disp('approximation of e^x on [0,1] with a uniform weight w(x)=1') +a11 = integrate('1','x',0,1); +a12 = integrate('x','x',0,1); +a13 = integrate('x*x','x',0,1); +a14 = integrate('x^3','x',0,1); +a21 = integrate('x','x',0,1); +a22 = integrate('x^2','x',0,1); +a23 = integrate('x^3','x',0,1); +a24 = integrate('x^4','x',0,1); +a31 = integrate('x^2','x',0,1); +a32 = integrate('x^3','x',0,1); +a33 = integrate('x^4','x',0,1); +a34 = integrate('x^5','x',0,1); +a41 = integrate('x^3','x',0,1); +a42 = integrate('x^4','x',0,1); +a43 = integrate('x^5','x',0,1); +a44 = integrate('x^6','x',0,1); + +c1 = integrate('exp(x)','x',0,1); +c2 = integrate('x*exp(x)','x',0,1); +c3 = integrate('x^2*exp(x)','x',0,1); +c4 = integrate('x^3*exp(x)','x',0,1); + +A = [a11 a12 a13 a14;a21 a22 a23 a24;a31 a32 a33 a34;a41 a42 a43 a44]; +C = [c1;c2;c3;c4]; +ann = inv(A)*C; +disp(ann, 'The coefficients a0,a1,a2,a3 are respectively : ' ); + +deff('[px]=p3(x)','px=ann(4)*x.^3+ann(3)*x.^2+ann(2)*x+ann(1)'); +x = [0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0]'; +e = exp(x); +p = p3(x); +err = e-p; +ann = [x e p err]; + +disp(ann,'Displaying the value of x exp(x) p3(x) exp(x)-p3(x) :'); +plot(x,err); +plot(x,zeros(length(x),1)); \ No newline at end of file -- cgit