Integrating a constant?

14 ビュー (過去 30 日間)
L'O.G.
L'O.G. 2023 年 8 月 8 日
コメント済み: Walter Roberson 2023 年 8 月 8 日
This is more of a physics question than a Matlab question, but given an instantaneous velocity vx and a time increment dt, how do you numerically integrate to get a displacement? Analytically, this would usually be pretty straightforward since you'd have a function for the velocity, but given that vx is just a number, how do you do this?

採用された回答

Walter Roberson
Walter Roberson 2023 年 8 月 8 日
format long g
constant = 1.23456;
constantFun = @(x) constant*ones(size(x));
attempt1 = integral(constantFun, 0, 10)
attempt1 =
12.3456
attempt2 = integral(@(x)constant, 0, 10, 'ArrayValued', true)
attempt2 =
12.3456
That is, the trick is that unless you use ArrayValued, integral() is going to pass in a vector of locations to integrate at, and you need to return a value for each of those locations. If you were to try integral(@(x)constant, 0, 10) then it would pass in a vector x but you would be only returning a scalar result no matter how big x was, and that would fail.
  2 件のコメント
L'O.G.
L'O.G. 2023 年 8 月 8 日
編集済み: L'O.G. 2023 年 8 月 8 日
Thanks, so that's numerically integrating over a function that is constant over the entire interval. Is that correct? Also, like in my original post (I know this is a conceptual question), does it even make sense to numerically calculate a displacement from an instantaneous velocity where the latter is a particular number rather than a function? I am trying to understand this.
Walter Roberson
Walter Roberson 2023 年 8 月 8 日
If what you have is a vector of times and a vector of corresponding vx, then you can use cumtrapz . That function would also be suitable if what you have is a constant time-step and a vector of vx over time.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by