Integrating cell2mat array

7 ビュー (過去 30 日間)
Edwin Espin
Edwin Espin 2021 年 4 月 21 日
コメント済み: Edwin Espin 2021 年 4 月 21 日
Hello, I have the message attached below and after I tried to use a function to integrate and sum two arrays that were converted from cells in a different code, how could I solve this? and is it possible to not use a function and instead use it directly the integration in the other code with that two cell2mat arrays? I appreciate any help.
function ECC = energy_consumption(ECC_1,ECC_2)
syms tt
ECC_1 = @(tt) ECC_1.*tt;
ECC_2 = @(tt) ECC_2.*tt;
ECC11 = int(ECC_1,5,10);
ECC22 = int(ECC_2,0,5);
[ECC] = ECC11 + ECC22;
end
Check for missing argument or incorrect argument data type in call to function 'int'.
Error in energy_consumption (line 6)
ECC11 = int(ECC_1,5,10);
Error in Electrical_Power_VMP_Kp_2 (line 147)
ECC(c) = energy_consumption(ECC_1,ECC_2)
  2 件のコメント
Jonas
Jonas 2021 年 4 月 21 日
if you want to integrate a vector you can use cumsum()
Edwin Espin
Edwin Espin 2021 年 4 月 21 日
thanks for your answer but I had to used each element individually

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

採用された回答

Walter Roberson
Walter Roberson 2021 年 4 月 21 日
function ECC = energy_consumption(ECC_1,ECC_2)
syms tt
ECC_1t = ECC_1.*tt;
ECC_2t = ECC_2.*tt;
ECC11 = int(ECC_1t, tt, 5,10);
ECC22 = int(ECC_2t, tt, 0,5);
[ECC] = ECC11 + ECC22;
end
Note that the result in ECC will be symbolic unless you convert it to double.
However, if the inputs ECC_1 and ECC_2 are numeric, then the integral of numbers times tt over a range of tt, can be calculated directly without any symbolic work:
int(NUMBER*tt, tt, A, B)
would be
(B^2-A^2)/2 * NUMBER
so
EC11 = (100-25)/2 * ECC_1;
EC21 = (25-0)/2 * ECC_2;
  1 件のコメント
Edwin Espin
Edwin Espin 2021 年 4 月 21 日
Thank you very much you answered my question

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by