Info

此问题已关闭。 请重新打开它进行编辑或回答。

Hi! I need to know how I can change this function in arrays!

1 次查看(过去 30 天)

Greetings! I have to do a function, but with arrays, that do the same that the function below. The outputs are the estimate value of pi (est) and the relative errors associate with each one. The outputs are vectors. The input is the maximum error that I can accept. The equation is the Leibniz equation to approximate pi. I don't want that the function gives me the terms, in this one! I have the function done, but I have to changed it in matriz, and remove the variable terms(ter) in the output. Thanks a lot ! 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 π.

function [ter,es,er]=ejercicio2d(x) %x is the maximum error that I want to accept % I don't want terms, only I want the others. 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

disp(['La cantidad de terminos necesarios usando la primera ecuacion: ', num2str(ter)]); disp(['El valor de PI estimado es: ',num2str(es)]); disp(['El error relativo asociado es: ',num2str(er)]); end

回答(0 个)

此问题已关闭。

Community Treasure Hunt

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

Start Hunting!

Translated by