Composite Trapez-ium Rule Approximation of Integral f(x)dx

In summary, an algorithm and Matlab function JN were created to use the Composite Trapezium Rule (CTR) to approximate the integral of an arbitrary function f of one variable. The inputs for the function are a, b, N, and f, and the output is the approximate integral value JNf. However, there may be an issue with defining f and using the feval command to apply the function to a specific function, such as f=3x+2. Further clarification on these aspects may be needed for the code to run successfully.
  • #1
sara_87
763
0

Homework Statement



Write an algorithm and Matlab function JN, which uses the Composite Trapez-
ium Rule (CTR) to compute an approximation of the integral f(x) dx for an arbitrary
function f of one variable. The inputs should be a, b and N (the number of
subintervals), and f (the name of a Matlab function of one variable). The
output should be the approximate integral value JNf, i.e. the result of the
Composite Trapezium Rule for f.


Homework Equations





The Attempt at a Solution



function JN=CTR(a,b,N)
h=(b-a)/N;
JN=0;
for i=1:N
ti=a+i*h;
ti1=a+(i-1)*h;
f=f(ti);
JN=JN+h/2*(f(ti1)+f(ti))
end

Most of it looks right but I'm sure i have done something wrong. is there something missing with defining f.
Thank you
 
Physics news on Phys.org
  • #2
Did you define f(x) somewhere? What's the point of f=f(ti) if you end up calling the function again anyway? The idea looks ok, it's just that you don't have all the specifics for MATLAB to me.
 
  • #3
Oh i think i get it now. no worries.
i have another question:
i have a function; like the one above, how do i apply it in another m file. i mean i want to apply this to the function f=3x+2 using feval command. this is what i did:
JN=feval(N,x);
y=3*x+2;
but if i type in the command: CTR(0,0.9,20); an error comes up.
How do we use the feval command?
Thank you.
 

What is the Composite Trapez-ium Rule Approximation of Integral f(x)dx?

The Composite Trapez-ium Rule Approximation of Integral f(x)dx is a numerical method used to approximate the value of a definite integral. It divides the interval of integration into smaller subintervals and uses the trapezoidal rule to estimate the area under the curve within each subinterval. The results from each subinterval are then combined to give an overall approximation of the integral.

How is the Composite Trapez-ium Rule Approximation of Integral f(x)dx calculated?

The Composite Trapez-ium Rule Approximation of Integral f(x)dx is calculated by dividing the interval of integration into smaller subintervals of equal width, h, and using the trapezoidal rule to estimate the area under the curve within each subinterval. The formula for the trapezoidal rule is: h/2 * (f(a) + 2f(x1) + 2f(x2) + ... + f(b)), where a and b are the endpoints of the subinterval and x1, x2, etc. are the intermediate points within the subinterval.

What are the advantages of using the Composite Trapez-ium Rule Approximation of Integral f(x)dx?

The Composite Trapez-ium Rule Approximation of Integral f(x)dx has several advantages. It is a relatively simple method to use and understand, making it accessible to those without advanced mathematical knowledge. It also provides a more accurate approximation compared to the basic trapezoidal rule, especially when the function being integrated is not linear. It can also handle functions with discontinuities or sharp corners, which may cause problems for other numerical integration methods.

What are the limitations of the Composite Trapez-ium Rule Approximation of Integral f(x)dx?

Like any numerical method, the Composite Trapez-ium Rule Approximation of Integral f(x)dx has its limitations. It is not exact and will always produce an approximation, which may not be precise enough for certain applications. It also requires the function to be continuous within the interval of integration, and may not be suitable for highly oscillatory functions. Additionally, the accuracy of the approximation depends on the number of subintervals used and the width of each subinterval, which may be time-consuming to determine.

When is the Composite Trapez-ium Rule Approximation of Integral f(x)dx most useful?

The Composite Trapez-ium Rule Approximation of Integral f(x)dx is most useful when a closed-form solution for the integral is not available or is difficult to obtain. It is also helpful when a quick approximation is needed, or when the function being integrated is not too complex. It is commonly used in engineering and science for numerical integration of real-world problems.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • Set Theory, Logic, Probability, Statistics
Replies
7
Views
1K
Replies
6
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
4K
  • Calculus and Beyond Homework Help
Replies
2
Views
1K
  • Calculus and Beyond Homework Help
Replies
4
Views
1K
  • Calculus and Beyond Homework Help
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
9K
Back
Top