Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters

1 visualización (últimos 30 días)
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 comentario
Xinmiao Wang
Xinmiao Wang el 18 de Feb. de 2021
This is my code for accelerated Maclaurin series, but I am stuck on (n)= 4(-1)^(n-1)/(2(n-1)+1)+pi_estimate for the above errors, even though I am not sure if my code is correct entirely, I want to fix this error first. I appreciate any help!

Iniciar sesión para comentar.

Respuestas (1)

Alan Stevens
Alan Stevens el 18 de Feb. de 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.

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by