Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please solve using the MATLAB program. Please follow the same format underneath the question. Recall that a geometric sum is a sum of the form
Please solve using the MATLAB program.
Please follow the same format underneath the question.
Recall that a geometric sum is a sum of the form a+ar+ar2+ar3+ (a) Write a function file called geomsum1 which accepts the values of r,a and n (in that order) as input arguments and uses a for loop to return the sum of the first n terms of the geometric series. Test your function for r=1/8,a=8,n=10. (b) Write a function file called geomsum2 which accepts the values of r,a and n (in that order) as input arguments and uses the built in command sum to find the sum of the first n terms of the geometric series. Test your function for r=1/8,a=8,n=10. Hint: Start by defining the vector e=[0:n1] and then evaluate the vector R=re. It should be easy to figure out how to find the sum from there. Part (a) NOTE: We must create separate functioin M-files here. The function will require input variables. Therefore, you cannot use 'run' to execute the function. You must invoke it by providing values for the input variables. Name the function geomsum 1 , then complete the follwing. Display contents of geomsum1 M-file Assign values to input variables r=??;a=??;n=??; NOTE: Do NOT define r,a, or n inside the function file. This defeats the purpose of requiring input arguments. Delete this note before submitting. Compute geometric sum for specified values of r,a, and n. geomsum1(??) Part (b) NOTE: MATLAB has several built in functions. Here, we want to use the built-in function "sum" to compute the same geometric sum as computed in part (a). The "sum" function takes a vector as input and sums its elements. Hence, we must create a vector containing all the terms of the sum we wish to compute and pass that vector as input to the sum function. Type "help sum" in command window for more info. Don't forget: the name of your function should be geomsum2. Delete this note before submissionStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started