cosine estimate taylor series
1 回表示 (過去 30 日間)
古いコメントを表示
sos, trying to fix in 30 min, not sure what is going wrong, im getiing 1.6985 e 5 and answer should be 0.6916.
function res = cosineEstimate(ang, k)
ang = '045-00-00'
k = 2
%DMS to degrees
angSplit = strsplit(ang, '-')
firstCell = angSplit(1)
angForm = str2double(firstCell)
%degree to rad
rad = (angForm/180)*pi;
r = 0;
for n = 1:k;
e = 2*n
f= factorial(e)
m = (-1)^(n)
r = r + m*(angForm^e)/f
res = r
end
end
0 件のコメント
回答 (2 件)
Sulaymon Eshkabilov
2022 年 2 月 22 日
Here is the corrected code:
ang = '045-00-00';
k = 2;
res = cosineEstimate(ang, k)
function res = cosineEstimate(ang, k)
%DMS to degrees
angSplit = strsplit(ang, '-');
firstCell = angSplit(1);
angForm = str2double(firstCell);
%degree to rad
RAD = (angForm/180)*pi;
res= 0;
for n = 1:k
res = res + ((-1) .^ (k-1) .* RAD .^ k) ./ factorial(k);
end
end
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!