Use trapezoidal method to find the deflection at each measurement point.

조회 수: 1 (최근 30일)
Sean Flanagan
Sean Flanagan 2022년 9월 30일
편집: Torsten 2022년 10월 1일
Hi,
I have the following 21x2 matrix
I need to use loops and trapezoidal method to find the deflection at each measurement point. By using the trapz command I can find the overall result but I need guidance with how to find the deflection at each measurement point.
  댓글 수: 1
Sean Flanagan
Sean Flanagan 2022년 10월 1일
cumtrapz gives me each answer for [f(x0)...f(x20]. Is there a way to write the code to give [f(x0)+f(x1)] = ans, [f(x0)+f(x1)+f(x2)] = ans, [f(x0)+f(x1)+f(x2)+f(x3)] = ans .....[f(x0)+f(x1)....+f(x19)+f(x20)] = ans, using for loops?

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

답변 (1개)

James Tursa
James Tursa 2022년 9월 30일
Sounds like you want the cumtrapz( ) function. If the assignment requires you to use loops, just code up the formula found in the trapz( ) doc:
  댓글 수: 4
Torsten
Torsten 2022년 10월 1일
편집: Torsten 2022년 10월 1일
Why
[f(x0)+f(x1)] = ans,
[f(x0)+f(x1)+f(x2)] = ans,
[f(x0)+f(x1)+f(x2)+f(x3)] = ans
.....
[f(x0)+f(x1)....+f(x19)+f(x20)] = ans ?
Don't you need
[f(x0)+f(x1)]/2 * (x1-x0) = ans
[f(x0)+f(x1)] / 2 *(x1-x0) + [f(x1)+f(x2)]/2 * (x2-x1) = ans,
[f(x0)+f(x1)] / 2 *(x1-x0) + [f(x1)+f(x2)]/2 * (x2-x1) + [f(x2)+f(x3)]/2 * (x3-x2) = ans
...
[f(x0)+f(x1)] / 2 *(x1-x0) + [f(x1)+f(x2)]/2 * (x2-x1) + [f(x2)+f(x3)]/2 * (x3-x2) + ... + [f(x19) + f(x20)]/2 * (x20-x19) = ans
?
That's what cumtrapz does.
Otherwise, use cumsum(f) instead of cumtrapz(x,f).
Sean Flanagan
Sean Flanagan 2022년 10월 1일
Thanks mate I must have done something wrong

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

카테고리

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

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by