フィルターのクリア

I need to change this function to arrays!

2 ビュー (過去 30 日間)
Anthony Fuentes
Anthony Fuentes 2016 年 10 月 18 日
コメント済み: Anthony Fuentes 2016 年 10 月 19 日
Greetings I need to change the function below to arrays. Instructions: Implement the equation (Leibniz- estimate pi [1/1 − 1 /3 + 1 /5 − 1/ 7 + 1 /9 − ⋯ = π /4 ]) in a function that receives the relative error willing to accept (x) and return the user a vector with all values of π estimated(es) and other vector with relative errors associated with each value of π. (er). Thanks a lot.
function [es,er]=ejercicio2d(x)
RT=pi;
ter=0;
estimado=1;
er=2*x;
while er>=x
z=((1^(ter)+(ter+1))/(ter+1))^((-1)^ter);
estimado=(estimado*z);
es=estimado* 2;
er=100*abs((es-RT)/RT);
ter=ter+1;
end
end

採用された回答

KSSV
KSSV 2016 年 10 月 19 日
function [es,er]=ejercicio2d(x)
RT=pi;
ter=0;
estimado=1;
er=2*x;
ER = [] ;
ES = [] ;
while er>=x
z=((1^(ter)+(ter+1))/(ter+1))^((-1)^ter);
estimado=(estimado*z);
es=estimado* 2;
er=100*abs((es-RT)/RT);
ter=ter+1;
ES(ter) = es ;
ER(ter) = er ;
end
end
If the loop length is known, can be initialized by dimension.
  1 件のコメント
Anthony Fuentes
Anthony Fuentes 2016 年 10 月 19 日
thanks a lot!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by