Calculate summation with loop or sum

11 ビュー (過去 30 日間)
Raja Ing
Raja Ing 2018 年 3 月 29 日
コメント済み: Raja Ing 2018 年 3 月 30 日
Hello,
I have to calculate and plot the attached equation in MatLab using a FOR loop or the sum function. Please Help me !
here is my code:
% code
clc
clear all;
f=(0:10e3:1e6);
a =-48.38 ;
b =0.41 ;
c =-25.32 ;
S1 = a.*f.^b+c;
Amp=[33.37,29.67,10.05,16.38];
Freq = [25.02e-3,34.30e-3,66.64e-3,88.25e-3];
Eca=[3.37,3.46,1.47,0.79];
S2=0;
for i=1:numel(Amp)
ai = Amp(i);
fi =Freq(i);
ei =Eca(i);
S2=S2+ai.*((-1)*exp((f-fi).^2./(2.*ei.^2)));
end
S=S1+S2;
figure(1)
plot(f,S,'*b','linewidth',1),
grid on

採用された回答

Torsten
Torsten 2018 年 3 月 29 日
for i=1:numel(f)
f_actual = f(i);
S(i) = a*f_actual^b+c+sum(Amp.*exp(-(f_actual-Freq).^2./(2*Eca.^2)));
end
plot(f,S)
I don't know the reason for the (-1) in your code.
Best wishes
Torsten.
  1 件のコメント
Raja Ing
Raja Ing 2018 年 3 月 30 日
Thanks for your help, it resolve my problem!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by