We are able to roughly calculate the area below the function using left/right riemann or…
- User
We are able to roughly calculate the area below the function using left/right riemann or trapezoid. In this lab we will calculate the area using 3 different methods and see which one was the most accurate. Here are the 3 methods: Approximate 1: Left Riemann: Ileft Approximate 2: Right Riemann: Iright Approximate 3: Trapezoidal: Itrap The obtained values Ileft, Iright, and Itrap should be saved in the cell array "intg" together with their corresponding names. For the details of the format, please refer to the follwoing example. In fact, a very accurate numerical integral result can be obtained by the MATLAB built in function "integral". You shall use this function to obtain Itrue as a benchmark. The differences between the numerical results obtained from above three methods with the benchmark solution should be calculated by |Ileft-Itrue|,|Iright-Itrue| and |Itrap-Itrue| respectively. The best method should have the smallest difference. The output variable "best" should be either of 'Left Riemann', 'Right Riemann', 'Trapezoidal'. For example when given myIntegral([0,5],10,@(x)x.^3+x.^2-10) the output of "intg" should be: intg=[{'Left Riemann'}, {'Right Riemann'}, {'Trapezoidal'};...{112.1875}, {187.1875}, {149.6875}]; best='Trapezoidal'; Tips you have to use: You should find the benchmark integral using the built-in function "integral". Be aware of the range you have set for the left and right riemann. The order of "intg" should be 'Left Riemann''Right Riemann''Trapezoidal' You are given the follwing code in matlab just fill it in: function [intg, best] = myIntegral(range,N,f) end
This is the code you will use to call your function: f = @(x) x.^3 + 2.*x -10; range = [0 10]; N = 100; [intg, best] = myIntegral(range,N,f)
- Assistant
Here is the completed code for the myIntegral function, which calculates the area under a curve using three different methods (Left Riemann, Right Riemann, and Trapezoidal) and compares them to the true benchmark value calculated by MATLAB's "integral" function:
MATLAB - User
A test tube filled with liquid of uniform density ρ , as shown in the figure, is spun in a centrifuge with angular frequency ω . (Figure 1)The test tube lies perpendicular to the axis of rotation of the centrifuge. The pressure in the fluid at the distance r0 from the axis of rotation is p0 . You may ignore the variation in pressure with depth; asume that it is much smaller than the variation in pressure with radius. What is the pressure p(r) of the fluid in the test tube at an arbitrary distance r from the axis of rotation? Express your answer in terms of ρ , r , ω , r0 , and p0 .
- Assistant
To find the pressure p(r) at an arbitrary distance r from the axis of rotation, we can use the equation of pressure in a rotating fluid:
dp = -ρω^2r dr
Let's integrate this equation with respect to r from r0 to r.
∫(dp) = -ρω^2 ∫(r dr) with integration limits [r0, r]
Integrating both sides, we get:
p(r) - p0 = -ρω^2 (1/2 * (r^2 - r0^2))
Now, we can solve for p(r):
p(r) = p0 + ρω^2 (1/2 * (r0^2 - r^2))
So, the pressure in the fluid at a distance r from the axis of rotation is:
p(r) = p0 + 1/2 * ρω^2 (r0^2 - r^2)