Hi! I need help with a function with arrays.
Afficher commentaires plus anciens
Hi! I need help with a function with arrays. I did a function that receive the n terms and the outputs are the relative error and the pi estimate value. But, I need to do but in the following way:
Instructions: Implement the equation in a function that receives the relative error willing to accept and return the user a vector with all values of π and other vector estimated with relative errors associated with each value of π. The equation is
pi/4= 1-1/3+1/5-1/7+1/9...- (Leibniz Equation)
The function that I have is the following:
%function
m=input('entre la cantidad de términos; ');
p=0;
for i=1: m
p=p-4*((-1)^(i-1)/(2*i*-1+1));
error=abs(pi-p);
if error <=0.01
break
end
end
disp('el numero de pi es;'); disp(p)
disp('El error cometido es;'); disp(error)
disp('La iteración final es:'); disp(i)
THANKS A LOT!
1 commentaire
Walter Roberson
le 15 Oct 2016
Please do not use error as the name of a variable: error is the key MATLAB routine for triggering error conditions.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Mathematics and Optimization dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!