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 个)
Alan Stevens
2021-2-18
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 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!