Question

1.1) Write a script in MATLAB that uses Reimann sum with 100 intervals (n=100) to calculate hydrostatic force of water on a t

0 0
Add a comment Improve this question Transcribed image text
Answer #1


. P= pg2 Here 0 = 1000 kg g 29.81 m² is allow Force d F 2 Pd A . 2PX W dz h. z (1-2) .=P4 h dz. oPX (1-2 da 20g ZX (7-2) dz T Matlab code for all types of integrations clear all close all %function for which integration have to do func=@(z) (1000*9.81%% Matlab function for Left Riemann integration function val=left_riemann(func, a,b,N) % func is the function for integration

%Matlab code for all types of integrations
clear all
close all
%function for which integration have to do
func=@(z) (1000*9.81.*z.*(7-z))/2;
fprintf('function for which integration have to do f(z)=')
disp(func)
%all limits
a=1; b=7;
fprintf('Upper and lower limit of integral h=%f to b=%f\n',a,b)
%number of subintervals
N=100;
%all integration value using different method
val1=left_riemann(func,a,b,N);
val2=right_riemann(func,a,b,N);
fprintf('For N = %d\n',N)
fprintf('\tIntegral value using left Reimann sum =%f\n',val1)
fprintf('\tIntegral value using Right Reimann sum =%f\n',val2)
%number of subintervals
N=500;
%all integration value using different method
val1=left_riemann(func,a,b,N);
val2=right_riemann(func,a,b,N);
fprintf('For N = %d\n',N)
fprintf('\tIntegral value using left Reimann sum =%f\n',val1)
fprintf('\tIntegral value using Right Reimann sum =%f\n',val2)

%integral using trapz
zz=linspace(a,b,100);
ff=func(zz);
val3=trapz(zz,ff);
fprintf('For n=%d, integral using trapz =%f\n',100,val3)

syms z
f(z)=(1000*9.81*z*(7-z))/2;
int_zz(z)=int(f,z);
fprintf('Integral using int function ')
disp(int_zz)
ext_val=double(int_zz(b)-int_zz(a));
fprintf('Integral value for limit h=%f to b=%f is %f\n',a,b,ext_val)

%Error values
error1=(((ext_val-val1))/ext_val)*100;
error2=(((ext_val-val2))/ext_val)*100;
error3=(((ext_val-val3))/ext_val)*100;

%Printing the result
fprintf('\tFor Left Reimann sum relative percent error is %e\n',error1)
fprintf('\tFor Right Reimann sum relative percent error is %e\n',error2)
fprintf('\tFor trapz relative percent error is %e\n',error3)

%%Matlab function for Left Riemann integration
function val=left_riemann(func,a,b,N)
    % func is the function for integration
    % a is the lower limit of integration
    % b is the upper limit of integration
    % N number of rectangles to be used
    val=0;
    %splits interval a to b into N+1 subintervals
    xx=linspace(a,b,N+1);
    dx=xx(2)-xx(1); %x interval
    %loop for Riemann integration
        for i=1:length(xx)-1
            xx1=xx(i);
            val=val+dx*double(func(xx1));
        end   
end
%%Matlab function for right Riemann integration
function val=right_riemann(func,a,b,N)
    % func is the function for integration
    % a is the lower limit of integration
    % b is the upper limit of integration
    % N number of rectangles to be used
    val=0;
    %splits interval a to b into N+1 subintervals
    xx=linspace(a,b,N+1);
    dx=xx(2)-xx(1); %x interval
    %loop for Riemann integration
        for i=2:length(xx)
            xx1=xx(i);
            val=val+dx*double(func(xx1));
        end   
end
%-------------- End of Code --------------%

Add a comment
Know the answer?
Add Answer to:
1.1) Write a script in MATLAB that uses Reimann sum with 100 intervals (n=100) to calculate...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • To Be Done Only in MatLab Please use the format provided: Integrals can be computed numerically using the Reimann sum...

    To Be Done Only in MatLab Please use the format provided: Integrals can be computed numerically using the Reimann sum definition. ゞrxldr ~-ofu.h where h = 부 when N is large, x, is the discretized points between a and b. For example the integral of f(x)2 for 03x3 2 is done by N-100; a-0 b 2; h -(b-a)/N; x-a:h:b; sum(f*h); F = The resulting value is 2.7068, compared to the exact solution 2.6667. Use the above technique to compute the...

  • please explain and do in matlab Problem 6. Consider the definite integral fo, sin(VE) cos( dz. Use n-100 and n = 300 separately, to find the Riemann sum for this integral. Keep at least four decim...

    please explain and do in matlab Problem 6. Consider the definite integral fo, sin(VE) cos( dz. Use n-100 and n = 300 separately, to find the Riemann sum for this integral. Keep at least four decimal places for your answer Problem 6. Consider the definite integral fo, sin(VE) cos( dz. Use n-100 and n = 300 separately, to find the Riemann sum for this integral. Keep at least four decimal places for your answer

  • Use matlab please. Exercise 2 Use the functions you coded in Exercise 1 to compute the...

    Use matlab please. Exercise 2 Use the functions you coded in Exercise 1 to compute the numerical approximation of the integral .1 cos e 30 To this end, write a Matlab/Octave function function [en,et , es] test-integration() = that returns the following items: em, et, es: row vectors with components the absolute values of the integration errors llref-Inl n=2.3, . . . . 100 obtained with the midpont (vector em), trapezoidal (vector et) and Simpson (vector es) rules. Here, f...

  • Write a script that prompts the user to enter a value n (n > 6) that...

    Write a script that prompts the user to enter a value n (n > 6) that will generate an n element vector of random integers between 0 and 100 that will represent quiz grades. Then have the script calculate the average of the quizzes where the smallest grade is dropped. Then script will display the average of the quizzes along with the highest quiz grade. Given the following system of equations: 8s - 11t + 7u + 5v - w...

  • Im not sure if this site uses MATLAB, but ill post the question anyway. MidPoint Rule...

    Im not sure if this site uses MATLAB, but ill post the question anyway. MidPoint Rule In this phase, we will evaluate the integral numerically using the definition by Riemann sum. For numerical calculations, we will use MATLAB software 3. First, use MATLAB to evaluate this time a definite integral x ехах For that, type directly into command window in MATLAB: syms x; int(x*exp(x),0,2). Get the answer in a number with at least four decimals. . Download an m-file, midPointRule.m,...

  • 1) a) Write MATLAB function that accepts a positive integer parameter n and returns a vector...

    1) a) Write MATLAB function that accepts a positive integer parameter n and returns a vector containing the values of the integral (A) for n= 1,2,3,..., n. The function must use the relation (B) and the value of y(1). Your function must preallocate the array that it returns. Use for loop when writing your code. b) Write MATLAB script that uses your function to calculate the values of the integral (A) using the recurrence relation (B), y(n) for n=1,2,... 19...

  • matlab help plz Overview: In this exercise, you will write code to compare how two different mumerical methods (a mi...

    matlab help plz Overview: In this exercise, you will write code to compare how two different mumerical methods (a middle Riemann sum, and MATLAB's integral function) evaluate the function fx) and the x-axis. The code should output the error between the two calculated areas. area between a Function Inputs Func- the function to be numerically integrated. a-the lower interval value. b-the upper interval value. N-the number of rectangles to be used. Function Outputs: Area Riemann- the numerical approximation for the...

  • Question 3 • Principle of Superposition: To obtain the net force on the test partide, add...

    Question 3 • Principle of Superposition: To obtain the net force on the test partide, add the y components of the forces from all the infinitesimal pieces of the rod from one end to the other. The sum of an infinite number of infinitesimal quantities is represented by an integral over the coordinate x that varies from 1/2 tox= 1/2 (substitute for dF, from Eq. A) į (substitute for Ffrom Eq. B) Pas = sine The variable of integration is...

  • MATLAB Create a function that provides a definite integration using Simpson's Rule Problem Summar This example demo...

    MATLAB Create a function that provides a definite integration using Simpson's Rule Problem Summar This example demonstrates using instructor-provided and randomized inputs to assess a function problem. Custom numerical tolerances are used to assess the output. Simpson's Rule approximates the definite integral of a function f(x) on the interval a,a according to the following formula + f (ati) This approximation is in general more accurate than the trapezoidal rule, which itself is more accurate than the leftright-hand rules. The increased...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT