Page 1 of 1

9. (16 pts) Match each code with the appropriate method: Composite Simpson's 1/3 Rule, Composite Simpson's 3/8 Rule, Com

Posted: Sat May 14, 2022 7:32 pm
by answerhappygod
9 16 Pts Match Each Code With The Appropriate Method Composite Simpson S 1 3 Rule Composite Simpson S 3 8 Rule Com 1
9 16 Pts Match Each Code With The Appropriate Method Composite Simpson S 1 3 Rule Composite Simpson S 3 8 Rule Com 1 (82.98 KiB) Viewed 43 times
9. (16 pts) Match each code with the appropriate method: Composite Simpson's 1/3 Rule, Composite Simpson's 3/8 Rule, Composite Trapezoid Rule, Linear Regression, Gauss-Quadrature, Newton's In- terpolating Polynomial, Lagrange Interpolating Polynomial, Forward Finite Difference O(h), Centered Finite Difference (ha), Backward finite difference O(h), Euler's Method, and Runge-Kutta 4th Order. a) function yint = prob1(x,y,xx) n = length(x); if length(y) =n, error('x and y must be same length'); end b = zeros(n,n); b(:,1) = y(:); for j = 2:n for i = 1:n-j+1 b(i,j) = (b(i+1,j-1)-b(i,j-1))/(x(i+j-1)-x(i)); end end xt = 1; yint = 5(1,1); for j = 1:n-1 xt = xt*(xx-x(j)); yint = yint+b(1,j+1)*xt; end b) function [t,y] = prob2(dydt,tspan,yo,h, varargin) if nargin<4, error(at least 4 input arguments required'), end ti = tspan (1);tf = tspan(2); if (tf>ti), error('upper limit must be greater than lower'), end t = (ti:h:tf)'; n = length(t); if t(n)<tf t(n+1) = tf; n = n+1; end y = y0*ones (n,1); for i = 1:n-1 y(i+1) = y(i) + dydt (t(i),y(i), varargin{:})*(t(i+1)-t(i)); end

c) function yint = prob3(x,y,xx) for j n = length(x); if length(y)*=n, error('x and y must be same length'); end s = 0; for i = 1:n product = y(i); = 1:n if i "= j product = product*(xx-x(j))/(x(i)-x(j)); end end s = s+product; end yint = s; d) function y = prob4(f,x1,x2,n) h = (x2-x1)/n; x(1) x1; sum = f(x1); for i=2:n-1 x(i)=x (i-1)+h; sum=sum+2*f(x(i)); end sum = sum + f(x2); int = sum*h/2; disp(int); end