Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The code language is in Matlab, Picture 1 is my lab#3 which works perfectly fine. Picture 2 is the error fixed for the flow chart.

image text in transcribed

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

The code language is in Matlab, Picture 1 is my lab#3 which works perfectly fine. Picture 2 is the error fixed for the flow chart. Picture 3 is the flow chart itself. Picture 4 is the instructions for lab#4 and picture 5 is the lab grader where I have to put the script of code in.

Picture 2 and 3 provided 2 alternative solutions to the way of solving the mistake

(this is the 3rd way) if Lab #3 code worked, it can be used as a starting point...the only thing is to adjust the code to store ALL the calculations of the series (i.e., each step in the for loop) rather than just the last one (as the code they created currently does). That should eliminate the need to go into detail on the top portion of the flowchart."

A good solution will receive an upvote!!

1 function [pi_estimate, error_absolute] = CL3_Maclaurin(n) 2 %% Input: 3 % N: The maximum desired order for the Maclaurin series estimate 4 %% 5 %% Outputs: 6 % pi_estimate: The estimate for pi produced by a Maclaurin series of order N 7 % error_absolute: The absolute value of the difference between the Matlab pi 8 % function and your estimate 9 %% Write your code here. num = 1; 11 for i=1:N num = num + ((-1)^i)/(2*i + 1); end pi_estimate = 4*num; 15 error_absolute = abs(pi_estimate-pi); 10 12 13 14 16 17 end 18 v = zeros (1,N+1), estimate=0, Mazeros(N+1,N+1) Flowchart For n = 1:N+1 CLE v(n) = (4 (-1)^ny((2n+1); estimate+=v(n) Wrong!!! Set M(1.1:N+1)=v(1:N+1) Return: estimate & M(N+1,1) For n = 1:N For j = 1,N-n+1 M(n+1.)=(M(n.j)+M(n.j+1))/2 1 ADE 2074 Computer Lab 2 ways: Instialize Pi, estimate=4 Vila 4 for n=2iNH v(n)=41-15h/(2n+1) +Pi-estimate P estimate = v(n) VT Copyright 2018 end v = zeros(1,N+1), estimate=0, Mezeros(N+1,N+1) Flowchart For n = 1:N+1 [ CLE v(n) = (4 (-1)^n./((21+1); estimatet=v(n) Return: estimate & M(N+1,1) Set M(1.1:N+1)=v(1:N+1) For n = 1:N 2 Don't initialize For i = 1,N-n+1 Min+1.j)=(M(n.j)+M(n.j+1))2 for ADE 2074 Computer Lab nali NxI Vans 46-1)^(n-1)/(2(n-1) +1) + Pi-estimate Pi_estimate = V(n) end VT VIRGINIA TECH V = zeros(1,N+1), estimate=0, M=zeros(N+1,N+1) For n = 1:N+1 CL#3 t v(n) = (4 (-1)^n)/((2n+1)); estimate+=v(n) Set M(1,1:N+1)=v(1:N+1) Return: estimate & M(N+1,1) For n = 1:N For j = 1,N-n+1 M(n+1,j)=(M(n,j)+M(n,j+1))/2 Exercise: Accelerated Maclaurin Series My Solutions In this lab you will compare the convergence of the original" pi sequence you developed in Lab 3 to an accelerated method that averages consecutive terms. You will complete two main tasks: 1) Apply Van Wijngaarden's acceleration to the Maclaurin series for pi you coded in Computer Lab #3. 2) Return the true relative error percentage for the original and accelerated series. You'll do this in the following series of steps. For Task #1: Change your code for CL3_Maclaurin so that it produces a row vector v(n) with all the pi estimates for n=0,...,N instead of only the Nth order estimate for pi. Note this row vector will have a size of N+1 and v(1) will be the estimate for order 0, v(2) will be the estimate for order 1, ..., V(N+1) will be the estimate for order N Allocate a matrix M of size N+1,N+1 Set the first row of the matrix as M(1.1:N+1) = v(1:N+1) Set the successive N rows using M(i+1,k) = 1/2*(M(i,k) + M(i,k+1)), for k = 1,...,N-i+1 and i=1,...,N Evaluate the accelerated estimate of pi as the element of M with position N+1,1, i.e., M(N+1,1) For Task #2: Evaluate the True Percent Relative Error of the original estimate Evaluate the True Percent Relative Error of the accelerated estimate Function Save C Reset LOMATLAB Documentation 1 function [eps_original, eps_accelerated] = CL4_PiEstimate(N) 2 % Input 3 % N: maximum value of n (refer to computer lab slides) 4 % Output 5 % eps_original: True Percent Relative Error of the original estimate 6 % eps_accelerated: True Percent Relative Error of the accelerated estimate 7 8 eps_original = 0; 9 eps_accelerated = 0; 10 11 %Vector and matrix needed for computation 12 V = zeros(1,N+1); 13 M = zeros(N+1,N+1); 14 pi_estimate=0; 15 16 %Write Your Code Here 17 18 19 end 20 1 function [pi_estimate, error_absolute] = CL3_Maclaurin(n) 2 %% Input: 3 % N: The maximum desired order for the Maclaurin series estimate 4 %% 5 %% Outputs: 6 % pi_estimate: The estimate for pi produced by a Maclaurin series of order N 7 % error_absolute: The absolute value of the difference between the Matlab pi 8 % function and your estimate 9 %% Write your code here. num = 1; 11 for i=1:N num = num + ((-1)^i)/(2*i + 1); end pi_estimate = 4*num; 15 error_absolute = abs(pi_estimate-pi); 10 12 13 14 16 17 end 18 v = zeros (1,N+1), estimate=0, Mazeros(N+1,N+1) Flowchart For n = 1:N+1 CLE v(n) = (4 (-1)^ny((2n+1); estimate+=v(n) Wrong!!! Set M(1.1:N+1)=v(1:N+1) Return: estimate & M(N+1,1) For n = 1:N For j = 1,N-n+1 M(n+1.)=(M(n.j)+M(n.j+1))/2 1 ADE 2074 Computer Lab 2 ways: Instialize Pi, estimate=4 Vila 4 for n=2iNH v(n)=41-15h/(2n+1) +Pi-estimate P estimate = v(n) VT Copyright 2018 end v = zeros(1,N+1), estimate=0, Mezeros(N+1,N+1) Flowchart For n = 1:N+1 [ CLE v(n) = (4 (-1)^n./((21+1); estimatet=v(n) Return: estimate & M(N+1,1) Set M(1.1:N+1)=v(1:N+1) For n = 1:N 2 Don't initialize For i = 1,N-n+1 Min+1.j)=(M(n.j)+M(n.j+1))2 for ADE 2074 Computer Lab nali NxI Vans 46-1)^(n-1)/(2(n-1) +1) + Pi-estimate Pi_estimate = V(n) end VT VIRGINIA TECH V = zeros(1,N+1), estimate=0, M=zeros(N+1,N+1) For n = 1:N+1 CL#3 t v(n) = (4 (-1)^n)/((2n+1)); estimate+=v(n) Set M(1,1:N+1)=v(1:N+1) Return: estimate & M(N+1,1) For n = 1:N For j = 1,N-n+1 M(n+1,j)=(M(n,j)+M(n,j+1))/2 Exercise: Accelerated Maclaurin Series My Solutions In this lab you will compare the convergence of the original" pi sequence you developed in Lab 3 to an accelerated method that averages consecutive terms. You will complete two main tasks: 1) Apply Van Wijngaarden's acceleration to the Maclaurin series for pi you coded in Computer Lab #3. 2) Return the true relative error percentage for the original and accelerated series. You'll do this in the following series of steps. For Task #1: Change your code for CL3_Maclaurin so that it produces a row vector v(n) with all the pi estimates for n=0,...,N instead of only the Nth order estimate for pi. Note this row vector will have a size of N+1 and v(1) will be the estimate for order 0, v(2) will be the estimate for order 1, ..., V(N+1) will be the estimate for order N Allocate a matrix M of size N+1,N+1 Set the first row of the matrix as M(1.1:N+1) = v(1:N+1) Set the successive N rows using M(i+1,k) = 1/2*(M(i,k) + M(i,k+1)), for k = 1,...,N-i+1 and i=1,...,N Evaluate the accelerated estimate of pi as the element of M with position N+1,1, i.e., M(N+1,1) For Task #2: Evaluate the True Percent Relative Error of the original estimate Evaluate the True Percent Relative Error of the accelerated estimate Function Save C Reset LOMATLAB Documentation 1 function [eps_original, eps_accelerated] = CL4_PiEstimate(N) 2 % Input 3 % N: maximum value of n (refer to computer lab slides) 4 % Output 5 % eps_original: True Percent Relative Error of the original estimate 6 % eps_accelerated: True Percent Relative Error of the accelerated estimate 7 8 eps_original = 0; 9 eps_accelerated = 0; 10 11 %Vector and matrix needed for computation 12 V = zeros(1,N+1); 13 M = zeros(N+1,N+1); 14 pi_estimate=0; 15 16 %Write Your Code Here 17 18 19 end 20

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Harness The Power Of Big Data The IBM Big Data Platform

Authors: Paul Zikopoulos, David Corrigan James Giles Thomas Deutsch Krishnan Parasuraman Dirk DeRoos Paul Zikopoulos

1st Edition

0071808183, 9780071808187

More Books

Students also viewed these Databases questions