Using an Array as an input

I am trying to compute the energy produced by a solar panel in a 24 hour period using a personally mde function computeEnergy.
function [Energy Total_Energy] = computeEnergy(Pan, t)
Energy = exp(-(((t-12)^2)/(1.5*sqrt(2*pi))));
Total_Energy = Pan*Energy;
end
While using t = [1:24] and Pan = 1 as inputs, I get the errors :
Error using ^ (line 51)
Incorrect dimensions for raising a matrix to a power. Check that the matrix is square and the power is a
scalar. To perform elementwise matrix powers, use '.^'.
Error in computeEnergy (line 8)
Energy = exp(-(((t-12)^2)/(1.5*sqrt(2*pi))));
I don't know where I need to incorporate new code to fix the problem.

回答 (1 件)

James Tursa
James Tursa 2021 年 4 月 21 日
編集済み: James Tursa 2021 年 4 月 21 日

1 投票

The error message actually tells you exactly what to do. Use element-wise operator .^ instead of the matrix operator ^
Energy = exp(-(((t-12).^2)/(1.5*sqrt(2*pi))));

1 件のコメント

James Wilson
James Wilson 2021 年 4 月 21 日
Thank that work

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

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

タグ

質問済み:

2021 年 4 月 21 日

コメント済み:

2021 年 4 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by