Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters
Afficher commentaires plus anciens
function [eps_original, eps_accelerated] = CL4_PiEstimate(N)
% Input
% N: maximum value of n (refer to computer lab slides)
% Output
% eps_original: True Percent Relative Error of the original estimate
% eps_accelerated: True Percent Relative Error of the accelerated estimate
eps_original = 0;
eps_accelerated = 0;
%Vector and matrix needed for computation
v = zeros(1,N+1);
M = zeros(N+1,N+1);
pi_estimate=0;
%Write Your Code Here
num = 1;
for n=1:N+1
v(n)= 4(-1)^(n-1)/(2(n-1)+1)+pi_estimate
pi_estimate=v(n)
end
Set M(1,1:N+1)=v(1:N+1)
for n = 1:N
for j = 1:N-n+1
M(n+1,j)=(M(n,j)+M(n,j+1))/2;
end
end
end
1 commentaire
Xinmiao Wang
le 18 Fév 2021
Réponses (1)
Alan Stevens
le 18 Fév 2021
Your line
v(n)= 4(-1)^(n-1)/(2(n-1)+1)+pi_estimate
should be
v(n)= 4*(-1)^(n-1)/(2*(n-1)+1)+pi_estimate
Note: | |
You need explicit multiplication signs here.
1 commentaire
Xinmiao Wang
le 18 Fév 2021
Catégories
En savoir plus sur Parallel Computing 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!