1

THE CODE NEEDS TO BE ON MATLAB 2. Exercise (a) Let's write a script file that...

Question

THE CODE NEEDS TO BE ON MATLAB 2. Exercise (a) Let's write a script file that...

THE CODE NEEDS TO BE ON MATLAB2. Exercise (a) Lets write a script file that calculates exp(2) by a Maclaurin series using a while loop exp x )=-+-+-+-+ The while loop should add each of the series terms. The program error as defined below is smaller than 0.01. Error is the exact value (i.e. exp(2)), minus the approximate value (i.e., the current series sum) should exit the loop when the absolute absolute error-lexact-approx Use fprintf within the loop such that, during each round of iteration, the number of iteration, current approximation (i.e. sum of series), and the absolute error are displayed. Also, report exact value once at the end of the program using fprintf. You can use built-in functions like factorial) and abs() The displayed result may look like the following lab8 4 iter- approx- 1.000, error 6.389 ter= 2, . (more lines like the above) exact value- (b) If you integrate cos(t) from t-0 to t-b, for what value of b does the integral become 0.5? You can refer to the program on the previous page. Use a while loop to stop iteration when the integral is 0.5 or above. Generate a text output on screen that reports the upper limit b and the integral.

2. Exercise (a) Let's write a script file that calculates exp(2) by a Maclaurin series using a while loop exp x )=-+-+-+-+ The while loop should add each of the series terms. The program error as defined below is smaller than 0.01. Error is the exact value (i.e. exp(2)), minus the approximate value (i.e., the current series sum) should exit the loop when the absolute absolute error-lexact-approx Use fprintf within the loop such that, during each round of iteration, the number of iteration, current approximation (i.e. sum of series), and the absolute error are displayed. Also, report exact value once at the end of the program using fprintf. You can use built-in functions like factorial) and abs() The displayed result may look like the following lab8 4 iter- approx- 1.000, error 6.389 ter= 2, . (more lines like the above) exact value- (b) If you integrate cos(t) from t-0 to t-b, for what value of b does the integral become 0.5? You can refer to the program on the previous page. Use a while loop to stop iteration when the integral is 0.5 or above. Generate a text output on screen that reports the upper limit b and the integral.

Answers

error=1; %starting value for error

maclaurin_value=0; % starting value for value calculated from maclaurin series

n=0; %starting power

x=2; %power to which e has to be raised to

i=0; %iteration number

while error > 0.01

      i=i+1; %increment iteration number

     maclaurin_value=maclaurin_value+ (x^n)/factorial(n);   %calculate approximation

     error=abs(exp(2)-maclaurin_value); %calculate error

     fprintf("iter = %d",i);

     fprintf(", approx = %f",maclaurin_value);

     fprintf(", error = %f \n",error);

     n=n+1;    %increment exponent to get the next term in the maclaurin series

end

fprintf("exact value = %f",exp(2));

Output of this script

iter= 1, approx = 1.000088, error= 6.389856 iter 2, approx = 3.ΘΘΘΘΘΘ, error = 4.389Θ56 iter = 3, approx = 5.000000, error = 2.389856 iter 4, approx= 6.333333, error = 1.055723 iter = 5, approx = 7.000000, error = θ. 389856 iter 6, approx 7.266667, error 0.122389 iter = 7, approx = 7.355556, error-8.633501 iter= 8, approx= 7.388952, error=8.008104 exact value = 7.389056

2. The second question refers to a program which is not included in the question. Please include the program which is (according to the question) available on the previous page.


Similar Solved Questions

1 answers
You have just been hired by FAB Corporation, the manufacturer of a revolutionary new garage door...
You have just been hired by FAB Corporation, the manufacturer of a revolutionary new garage door opening device. The president has asked that you review the company's costing system and do what you can to help us get better control of our manufacturing overhead costs." You find that the comp...
1 answers
Suppose that all consumers view red pencils and blue pencils as perfect substitutes. Suppose that the...
Suppose that all consumers view red pencils and blue pencils as perfect substitutes. Suppose that the supply curve for red pencils is upward sloping. Let the price of red pencils and blue pencils be pr and pb. What would happen if the government put a tax only on red pencils?...
1 answers
You have two samples of egg whites. The first sample is mixed with a bit of...
You have two samples of egg whites. The first sample is mixed with a bit of table salt and the second sample is mixed with a bit of white vinegar. Now both samples are placed in a frying pan. Would the samples cook faster than just egg whites themselves? If so, explain the chemistry behind it....
1 answers
Chubbs Inc's manufacturing overhead budget for the first quarter of 2020 contained the following data. Variable...
Chubbs Inc's manufacturing overhead budget for the first quarter of 2020 contained the following data. Variable Costs Fixed Costs Indirect materials $11300 Supervisory salaries $37,000 Indirect labor 10,800 Depreciation 6,000 Property taxes and insurance Utilities 7,200 7,400 Maintenance 5,900 M...
1 answers
2. Let Xi, X2, and X represent the times necessary to perform three successive repair tasks...
2. Let Xi, X2, and X represent the times necessary to perform three successive repair tasks at a certain service facility. Suppose they are independent normal random variables with expected values μι μ2, and ,13 and variances σ σ and σ3 respectively. a. If,-μ2-13-65 a...
1 answers
Supply the missing nuclear symbol in each of the following equations for bombardment reactions. a. ?...
Supply the missing nuclear symbol in each of the following equations for bombardment reactions. a. ? + ^4_2 alpha rightarrow 6250_99 Es + ^3_1 H b. ^14_7 N + ^4_2 alpha rightarrow ? + H c. ^12_6 C + ^2_1 H rightarrow ^13_7 N + ? d. ^27_13 Al + ? rightarrow ^30_15 P + ^1_0 n...
1 answers
5.3.21 trial repeated n times. Use the binomial probablity formulia to fnd the probebilty of x...
5.3.21 trial repeated n times. Use the binomial probablity formulia to fnd the probebilty of x successes alven the probability p of success on a singls trial Assume that a procedure ylelds a binomial distribution witha P)Round to three decimal places as needed )...
1 answers
1. The probability that Justin will play golf today is 60%, the probability that he will...
1. The probability that Justin will play golf today is 60%, the probability that he will play golf tomorrow is 75%, and the probability that he will play golf on both days is 50%. What is the probability that he does not play golf on either day? 2. If 28% of the population of Statesville wears conta...
1 answers
ССП B) security analysis 16) The efficient market hypothesis suggests that A) active portfolio management strategies...
ССП B) security analysis 16) The efficient market hypothesis suggests that A) active portfolio management strategies are the most appropriate investment strategies B) a bottom-up approach is the most appropriate investment strategy either active or passive strategies may be appropr...
1 answers
How do you find the x and y intercept given (4, -2), (5, -4)?
How do you find the x and y intercept given (4, -2), (5, -4)?...
1 answers
PART I – SQL Data Control Language and Views: The users of the Medical database include...
PART I – SQL Data Control Language and Views: The users of the Medical database include three nurses (nurse_1, nurse_2, and nurse_3), three physicians (doc_1, doc_2, and doc_3), and one manager (manager_1), all of whom have been created by the DBA. You are asked to use SQL to create necessary ...
1 answers
Digital Circuits 1) Draw block diagrams to implement a 4 to 1 with 4 bits multiplexer. The data i...
Digital Circuits 1) Draw block diagrams to implement a 4 to 1 with 4 bits multiplexer. The data input lines are 4 bits wide. Please decide how many selects do you need. And write the final equation for inputs and output in both your report and block diagram. Do the simulation....
1 answers
Plz solv quickly s 03) (2+2+2+1-7 marks) Let X have a Poisson distribution with parameter i-9....
plz solv quickly s 03) (2+2+2+1-7 marks) Let X have a Poisson distribution with parameter i-9. a. What value of a such that P(x2 a) 0.005 b. Compute P(3 <x <10) c. Compute P (x9)...
1 answers
Ae 2 questions for 25 marks each. 1. A horn antenna is designed to radiate at...
ae 2 questions for 25 marks each. 1. A horn antenna is designed to radiate at 3 GHz for space communication. Design a patch antenna for the same frequeney that can be mounted on space craft. Show your detail work in...
1 answers
Suppose on December 31, Hipzone Inc. needs to record depreciation on a piece of office equipment....
Suppose on December 31, Hipzone Inc. needs to record depreciation on a piece of office equipment. The equipment was purchased on 1/1/2010 for $2,000, was expected to last 10 years at the time of purchase, and had an expected salvage value of $200. No depreciation has been recorded on the equipment f...

-- 0.011324--