フィルターのクリア

How would I sum a function and use fzero?

1 回表示 (過去 30 日間)
John Nosh
John Nosh 2017 年 10 月 22 日
コメント済み: Andrei Bobrov 2017 年 10 月 22 日
I want a function to look like this y=sin(t1-T)+sin(t2-T)+sin(t3-T)+...+sin(tn-T) and use the fzero to find T. How would I go about this? Thank you in advance.

回答 (3 件)

Roger Stafford
Roger Stafford 2017 年 10 月 22 日
編集済み: Roger Stafford 2017 年 10 月 22 日
Using ‘fzero’ on that particular problem is needlessly inefficient. You can use ‘atan2’ and ‘asin’ instead.
cn = cos(t1)+cos(t2)+...+cos(tn);
sn = sin(t1)+sin(t2)+...+sin(tn);
p = atan2(sn,cn);
as = asin(y/sqrt(sn^2+cn^2));
T1 = p-as; % One solution (in radians)
T2 = p+as-pi; % Another solution (in radians)
Also any multiple of 2*pi added or subtracted from T1 or T2 is a solution. (Note that the inequality y^2<=sn^2+cn^2 must be true for a solution to exist.)

Birdman
Birdman 2017 年 10 月 22 日
t=0:0.1:10;syms T y(T);
for i=1:1:length(t)
yy(i)=sin(t(i)-T);
end
y=symfun(sum(yy),T);
fzero(y,0.5)
Hope this helps.
  2 件のコメント
J. Nash
J. Nash 2017 年 10 月 22 日
Many thanks this was a great help. I couldn't get my head around it.
Birdman
Birdman 2017 年 10 月 22 日
Can you accept the answer so that other people having the same problem will know that there is a working solution?

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


Andrei Bobrov
Andrei Bobrov 2017 年 10 月 22 日
f = @(T)sum(sin(t(:) - T))
fzero(f,.5)
  1 件のコメント
J. Nash
J. Nash 2017 年 10 月 22 日
Wow this is even shorter. Helps a lot since I have around 1000 lines of code. Many thanks for making my code easier.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by