Integrating function of t over numerical values

1 回表示 (過去 30 日間)
Ragini Ravichandren
Ragini Ravichandren 2019 年 10 月 21 日
編集済み: Ragini Ravichandren 2019 年 10 月 21 日
Has anyone ever experienced the following errors when attempting to integrate a function handle with respect to a certain variable? I followed the commands used to calculate an integral, and found myself with the following problems. Any advice would be greatly appreciated!

採用された回答

Bjorn Gustavsson
Bjorn Gustavsson 2019 年 10 月 21 日
Yes, that means that the function you call integral with is called with an array of values - therefore your function (the long expression) should manage that. The way you've written it you will, implicitly, call it with arrays for t - so you'll have to replace ^ (which is the matrix-power in matlab) to .^ (which is the elementwise power), and where you have t*cos(t) (or the like) you'll also have to change from matrix-multiplication (*) to element-wise multiplication (.*).
HTH
  1 件のコメント
Ragini Ravichandren
Ragini Ravichandren 2019 年 10 月 21 日
編集済み: Ragini Ravichandren 2019 年 10 月 21 日

Got it, thanks! I was wondering, however, I also wanted to use the solve(eqn, Y) function, in order to set the equation equal to s and solving for g. Will changing the equation to element wise also allow use of the solve function?

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

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2019 年 10 月 21 日
F = str2func(vectorize(FUN));
Q = integral(F,0,6);

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by