How to create a function as sum of some sine functions?

31 ビュー (過去 30 日間)
Klaudjo Aliaj
Klaudjo Aliaj 2021 年 1 月 6 日
コメント済み: Star Strider 2021 年 1 月 8 日
I am trying to create a function which looks like:
,
but I am not finding the way how do it it. Can someone help me?
  1 件のコメント
SHIVAM KUMAR
SHIVAM KUMAR 2021 年 1 月 6 日
Is your theta in radians or degrees ?

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

採用された回答

Star Strider
Star Strider 2021 年 1 月 6 日
A loop is not necessary.
If you have R2016b or later, try this (using your own variable vectors):
t = linspace(0, 2, 750); % Time Vector
a = 1:10; % Amplitude Vector
f = linspace(1000, 2000, numel(a)); % Frequency Vector
th = linspace(-pi, pi, numel(a)); % Phase Vector
y = sum(a(:).*sin(2*pi*f(:)*t + th(:))); % Compute Function, Then Take Sum Of Rows
figure
plot(t, y)
grid
This uses automatic implicit expansion, introduced in R2016b. If you have an earlier version:
y = sum(bsxfun(@times, a(:), sin(2*pi*f(:)*t + th(:)))); % Compute Function, Then Take Sum Of Rows
produces the same result.
.
  2 件のコメント
Klaudjo Aliaj
Klaudjo Aliaj 2021 年 1 月 8 日
Thank you :)
Star Strider
Star Strider 2021 年 1 月 8 日
As always, my pleasure!

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

その他の回答 (1 件)

SHIVAM KUMAR
SHIVAM KUMAR 2021 年 1 月 6 日
編集済み: SHIVAM KUMAR 2021 年 1 月 6 日
This can be done like
y=0; %necessary to add the other things
for i=1:length(a)
y=y+a(i).*sind(2*pi*f(i).*t+theta(i));
end
If this works accept this answer but
if this does not work tell the error/other requirements in comment

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by