Effacer les filtres
Effacer les filtres

I need to change this function to arrays!

2 vues (au cours des 30 derniers jours)
Anthony Fuentes
Anthony Fuentes le 18 Oct 2016
Commenté : Anthony Fuentes le 19 Oct 2016
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

Réponse acceptée

KSSV
KSSV le 19 Oct 2016
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.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by