Evaluation of Integration without Loops

조회 수: 2 (최근 30일)
Ahmad Gad
Ahmad Gad 2021년 1월 13일
답변: Ahmad Gad 2021년 2월 9일
Hello all.
I have a mathematical expression takes the following form,
where C is known scalar, and or is known vector. The question here is, Does MATLAB have some functions to evaluate this integral function without using loops (I have the solution with for loop)?
I am trying to look for the minimum time the PC takes to evaluate the function becasue I am optimizing the scalar C against some objective function. For example, does conv() can help here by anyhow?
Thanks a lot,
Ahmad

채택된 답변

Ahmad Gad
Ahmad Gad 2021년 2월 9일
I fixed it using cumtrapz() function.

추가 답변 (1개)

madhan ravi
madhan ravi 2021년 1월 13일
help trapz
TRAPZ Trapezoidal numerical integration. Z = TRAPZ(Y) computes an approximation of the integral of Y via the trapezoidal method (with unit spacing). To compute the integral for spacing different from one, multiply Z by the spacing increment. For vectors, TRAPZ(Y) is the integral of Y. For matrices, TRAPZ(Y) is a row vector with the integral over each column. For N-D arrays, TRAPZ(Y) works across the first non-singleton dimension. Z = TRAPZ(X,Y) computes the integral of Y with respect to X using the trapezoidal method. X can be a scalar or a vector with the same length as the first non-singleton dimension in Y. TRAPZ operates along this dimension. If X is scalar, then TRAPZ(X,Y) is equivalent to X*TRAPZ(Y). Z = TRAPZ(X,Y,DIM) or TRAPZ(Y,DIM) integrates across dimension DIM of Y. The length of X must be the same as size(Y,DIM)). Example: Y = [0 1 2; 3 4 5] trapz(Y,1) trapz(Y,2) Class support for inputs X, Y: float: double, single See also SUM, CUMSUM, CUMTRAPZ, INTEGRAL. Documentation for trapz doc trapz Other functions named trapz codistributed/trapz gpuArray/trapz
  댓글 수: 1
Ahmad Gad
Ahmad Gad 2021년 1월 13일
Is it possible to do it using a single trapz? I understand that I have to involve the trapz inside a loop becasue the upper limit of the integral is variable t.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by