please just help me write a matlab code that will calculate the simpsons rule fo
ID: 1841789 • Letter: P
Question
please just help me write a matlab code that will calculate the simpsons rule for the numerator divided by the denominator
The company BigDig designs the reservoir for liquid chemicals of depth D 100 ft. The chemicals exert pressure on the face of the reservoir dam as shown in Figure. You are the company engineer and your task is to calculate pressure distribution on the reservoir dam and find point of application of pressure force. The gage pressure can be obtained from hydrostatic differential equation: (1) az where ye is the specific weight of liquid. The boundary condition is p o) 0, that is, the gage pressure at the liquid surface is equal to zero. Simplified method (denoted as S that you learned in Fluids-1 adopted average constant specific weight. Yav Note that for this S method the pressure increases linearly with depth, p z yav In this project you will compare S method to more comprehensive ways based on numerical integration. The pressure force can be determined by multiplying pressure times the area of the dam face. Because both pressure p(z) and width of the dam face w (z) vary with depth, the total pressure force F is obtained by evaluating F Sp( 2)wa dr. The line of action of pressure force can be obtained by evaluating (2)Explanation / Answer
Using following code you can calculate numerator and denominator seperately and then use it to calculate line of action of pressure. ########################################### function I = simpsons(f,a,b,n) % This function computes the integral "I" via Simpson's rule in the interval [a,b] with n+1 equally spaced points % % Syntax: I = simpsons(f,a,b,n) % % Where, % f= can be either an anonymous function (e.g. f=@(x) sin(x)) or a vector % containing equally spaced values of the function to be integrated % a= Initial point of interval % b= Last point of interval % n= # of sub-intervals (panels), must be integer % % Written by Juan Camilo Medina - The University of Notre Dame % 09/2010 (copyright Dr. Simpson) % % % Example 1: % % Suppose you want to integrate a function f(x) in the interval [-1,1]. % You also want 3 integration points (2 panels) evenly distributed through the % domain (you can select more point for better accuracy). % Thus: % % f=@(x) ((x-1).*x./2).*((x-1).*x./2); % I=simpsons(f,-1,1,2) % % % Example 2: % % Suppose you want to integrate a function f(x) in the interval [-1,1]. % You know some values of the function f(x) between the given interval, % those are fi= {1,0.518,0.230,0.078,0.014,0,0.006,0.014,0.014,0.006,0} % Thus: % % fi= [1 0.518 0.230 0.078 0.014 0 0.006 0.014 0.014 0.006 0]; % I=simpsons(fi,-1,1,[]) % % note that there is no need to provide the number of intervals (panels) "n", % since they are implicitly specified by the number of elements in the % vector fi if numel(f)>1 % If the input provided is a vector n=numel(f)-1; h=(b-a)/n; I= h/3*(f(1)+2*sum(f(3:2:end-2))+4*sum(f(2:2:end))+f(end)); else % If the input provided is an anonymous function h=(b-a)/n; xi=a:h:b; I= h/3*(f(xi(1))+2*sum(f(xi(3:2:end-2)))+4*sum(f(xi(2:2:end)))+f(xi(end))); end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.