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

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

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!

댓글을 달려면 로그인하십시오.

답변 (1개)

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.

카테고리

도움말 센터File Exchange에서 Parallel Computing에 대해 자세히 알아보기

질문:

2021년 2월 18일

댓글:

2021년 2월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by