From f35ea80659b6a49d1bb2ce1d7d002583f3f40947 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Tue, 10 Oct 2017 12:38:01 +0530 Subject: updated the code --- 75/CH5/EX5.4/ex_4.sce | 6 +++--- 75/CH5/EX5.5/ex_5.sce | 10 +++++----- 75/CH5/EX5.7/ex_7.sce | 29 +++++++++++++++++++++++++++++ 75/CH5/EX5.8/ex_8.sce | 33 +++++++++++++++++++++++++++++++-- 4 files changed, 68 insertions(+), 10 deletions(-) (limited to '75/CH5') diff --git a/75/CH5/EX5.4/ex_4.sce b/75/CH5/EX5.4/ex_4.sce index d14b592d2..d661f5067 100755 --- a/75/CH5/EX5.4/ex_4.sce +++ b/75/CH5/EX5.4/ex_4.sce @@ -1,4 +1,4 @@ - // PG (258) +// PG (258) deff('[y]=f(x)','y=exp(x)*cos(x)') x0=0; @@ -7,7 +7,7 @@ x=x0:xn; // True value -I = integrate('exp(x)*cos(x)','x',x0,x1) +I = integrate('exp(x)*cos(x)','x',x0,xn) // Using Simpson's rule @@ -35,4 +35,4 @@ x5=x0+5*h; x6=x0+6*h; x7=x0+7*h; x8=x0+8*h; - I3 = h*(f(x0)+4*f(x1)+2*f(x2)+4*f(x3)+2*f(x4)+4*f(x5)+2*f(x6)+4*f(x7)+f(x8))/3 + I3 = h*(f(x0)+4*f(x1)+2*f(x2)+4*f(x3)+2*f(x4)+4*f(x5)+2*f(x6)+4*f(x7)+f(x8))/3 \ No newline at end of file diff --git a/75/CH5/EX5.5/ex_5.sce b/75/CH5/EX5.5/ex_5.sce index 541b7d0a3..cf8514ce0 100755 --- a/75/CH5/EX5.5/ex_5.sce +++ b/75/CH5/EX5.5/ex_5.sce @@ -1,4 +1,4 @@ - // PG (261) +// PG (261) // Example 1 @@ -9,11 +9,11 @@ deff('[y]=fppp(x)','y=(105*sqrt(x))/8') deff('[y]=fpppp(x)','y=(105*x^(-0.5))/16') x0=0; -x1=1; -x=x0:x1; +xn=1; +x=x0:xn; // True value -I = integrate('x^(7/2)','x',x0,x1) +I = integrate('x^(7/2)','x',x0,xn) // Using Trapezoidal rule @@ -43,4 +43,4 @@ x2=x0+2*h; x3=x0+3*h; x4=x0+4*h; I2 = h*(f(x0)+4*f(x1)+2*f(x2)+4*f(x3)+f(x4))/3 - E2 = -h^4*(xn-x0)*fpppp(0.5)/180 + E2 = -h^4*(xn-x0)*fpppp(0.5)/180 \ No newline at end of file diff --git a/75/CH5/EX5.7/ex_7.sce b/75/CH5/EX5.7/ex_7.sce index a1608ff35..6eb53781d 100755 --- a/75/CH5/EX5.7/ex_7.sce +++ b/75/CH5/EX5.7/ex_7.sce @@ -1,3 +1,32 @@ +function [pL] = legendrepol(n,var) + +// Generates the Legendre polynomial +// of order n in variable var + +if n == 0 then + cc = [1]; +elseif n == 1 then + cc = [0 1]; +else + if modulo(n,2) == 0 then + M = n/2 + else + M = (n-1)/2 + end; + + cc = zeros(1,M+1); + for m = 0:M + k = n-2*m; + cc(k+1)=... + (-1)^m*gamma(2*n-2*m+1)/(2^n*gamma(m+1)*gamma(n-m+1)*gamma(n-2*m+1)); + end; +end; + +pL = poly(cc,var,'coeff'); +endfunction + +// End function legendrepol + // PG (277) deff('[y]=f(x)','y=exp(x)*cos(x)') diff --git a/75/CH5/EX5.8/ex_8.sce b/75/CH5/EX5.8/ex_8.sce index d0d40fc93..c5baa6329 100755 --- a/75/CH5/EX5.8/ex_8.sce +++ b/75/CH5/EX5.8/ex_8.sce @@ -1,3 +1,32 @@ +function [pL] = legendrepol(n,var) + +// Generates the Legendre polynomial +// of order n in variable var + +if n == 0 then + cc = [1]; +elseif n == 1 then + cc = [0 1]; +else + if modulo(n,2) == 0 then + M = n/2 + else + M = (n-1)/2 + end; + + cc = zeros(1,M+1); + for m = 0:M + k = n-2*m; + cc(k+1)=... + (-1)^m*gamma(2*n-2*m+1)/(2^n*gamma(m+1)*gamma(n-m+1)*gamma(n-2*m+1)); + end; +end; + +pL = poly(cc,var,'coeff'); +endfunction + +// End function legendrepol + // PG (278) deff('[y]=f(x)','y=exp(-x^2)') @@ -22,7 +51,7 @@ for j = 1:2 A = [A 2/((1-xr(j)^2)*(horner(pd,xr(j)))^2)] end -tr = ((x1-x0)/2.*xr)+((x1+x0)/2); +tr = ((x1-x0)./2.*xr)+((x1+x0)./2); -s = ((x1-x0)/2)*f(tr) +s = ((x1-x0)./2).*f(tr) I = s*A \ No newline at end of file -- cgit