Borrar filtros
Borrar filtros

I need to change this function to arrays!

2 visualizaciones (últimos 30 días)
Anthony Fuentes
Anthony Fuentes el 18 de Oct. de 2016
Comentada: Anthony Fuentes el 19 de Oct. de 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

Respuesta aceptada

KSSV
KSSV el 19 de Oct. de 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.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by