Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

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

조회 수: 1 (최근 30일)
Anthony Fuentes
Anthony Fuentes 2016년 10월 18일
마감: MATLAB Answer Bot 2021년 8월 20일

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