Filter löschen
Filter löschen

I need to change this function to arrays!

2 Ansichten (letzte 30 Tage)
Anthony Fuentes
Anthony Fuentes am 18 Okt. 2016
Kommentiert: Anthony Fuentes am 19 Okt. 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

Akzeptierte Antwort

KSSV
KSSV am 19 Okt. 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.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by