Question

In: Computer Science

Computing Assignment 1 You must upload both your code (to Assignment 1 scripts/codes) and your report...

Computing Assignment 1
You must upload both your code (to Assignment 1 scripts/codes) and your report (to Assignment
1 computing report). The assignment is due at 11:00pm. I have set the due time in Canvas to
11:05pm and if Canvas indicates that you submitted late, you will be given 0 on the assignment.
Your computing report must be exactly 1 page. There will be a penalty given if your report is
longer than one page.
• Please read the Guidelines for Assignments first.
• Keep in mind that Canvas discussions are open forums.
• Acknowledge any collaborations and assistance from colleagues/TAs/instructor.
Computing Assignment { Floating Point Arithmetic
Required submission: 1 page PDF document and Matlab scripts uploaded to Canvas.
1. Part 1 - warmup
Use Matlab and issue the following two commands on the command line: sin(0); sin(π). State
your answer and explain the answer you see. This should be done in one or two sentences at
the beginning of your report.
2. Part 2
Let 8 ≤ x ≤ 10 be an arbitrary number and n a nonnegative integer. In exact arithmetic, the
following computation leaves x unchanged:
1 for i=1:n

2 x=5 log(x);

3 end

4

5 for i=1:n

6 x=exp(x/5.0);

7 end

However, in finite-precision arithmetic the results may be dramatically different for large n.
The purpose of this assignment is to investigate the output of this computation in Matlab for
various values of n and for x in the range 8 ≤ x ≤ 10.
Your conclusions should be explained in a one-page report. Your report must include the
following:
(a) Representative plots of the output as a function of x, with each plot corresponding to a
different value of n.
(b) A discussion of the smallest value of n after which the result of the finite-precision
computation begins to differ from exact arithmetic computation.
1
(c) A discussion of the limiting behaviour for large n.
(d) A brief explanation as to why computing in floating point arithmetic leads to the results
you have found.
Partial code for this assignment can be found in the file FloatPt.m on Canvas. I suggest
using this as your starting point. If you have questions about Matlab or other aspects of
the assignment or course, then I strongly encourage you to attend the tutorials and drop-in
workshops.

----------------Codes given----------------------

% MACM 316 - Homework 1
% Floating Point Arithmetic with logarithm function
% Description: Performs n-fold logarithm followed by n-fold exponentiation
% File name: FloatPt_log.m

clear
%format long; %this changes the number of decimal digits that DISPLAY
n=30;
st=0.001; % Define a stepsize
x=8:st:10; % x is a row vector of numbers between 1.3 and 2.3 of increments st
y=x;

for i=1:n
    y=5*log(y);
end
%y(1) %this is how you print the 1st element of y to the screen
%y(11)
%y(101)
%y(1001)
%pause %this stops your program until you press a key
for i=1:n
    y=exp(y/5.0); 
end
%y(1)
%y(11)
%y(101)
%y(1001)
% Plot the output y versus the input x
plot(x,y) %you can change the title and axis labels in this manner
title(['Output of the Computation with n = ' num2str(n)],'fontsize',14)
xlabel(['Input x'],'fontsize',12)
ylabel(['Output y'],'fontsize',12)

Solutions

Expert Solution

Note: Done accordingly. Please comment for any problem. Please Uprate. Thanks.

Updated code:

% MACM 316 - Homework 1
% Floating Point Arithmetic with logarithm function
% Description: Performs n-fold logarithm followed by n-fold exponentiation
% File name: FloatPt_log.m

clear
%format long; %this changes the number of decimal digits that DISPLAY

st=0.001; % Define a stepsize
for n=30:40
x=8:st:10; % x is a row vector of numbers between 8 and 10 of increments st
y=x;
fprintf("Original Value of last element of y is %f\n",y(end));
for i=1:n
y=5*log(y);
end
fprintf("Value of last element of y=log(x) for n = %d is %.31f\n",n,y(end));
for i=1:n
y=exp(y/5.0);
end
fprintf("Getting back original value of last element for n = %d is %.31f\n\n",n,y(end));
plot(x,y,'LineWidth',2,'DisplayName', ['n=' num2str(n)])
hold on
end
title(['Output of the Computation with different n values '])
xlabel(['Input x'],'fontsize',12)
ylabel(['Output y'],'fontsize',12)
legend('show','Location','NorthEastOutside');

Part 1:

Matlab works of floating-point arithmetic, 0 can be accurately represented, and sin(0) can also be exactly represented in Matlab. Some floating-point numbers cannot be represented exactly in binary forms like pi and the way Matlab calculates sin internally. So that's why we are seeing the very small but non zero result.

Part 2:

a)

b) As we can see for value o n=33 it starts getting shaky, and after that beyond n=37 we start getting direct result due to precision error.

c) and d) As we can see in the right figure as we increase the value of y due to increase in floating-point error we are deviating far away from the original value. It is because Matlab performs floating-point arithmetic and perform round off to present the result. However, when floating-point error increases too much due to results going beyond the precision we are getting too much deflection from the original value.


Related Solutions

Read the assignment and answer the questions. You must also upload your Excel file, Word document...
Read the assignment and answer the questions. You must also upload your Excel file, Word document or pdf showing your work. Bodacious Building Co. is considering four different acquisition methods for obtaining pickup trucks. If the contractor’s MARR is 6%, which alternative do you recommend? The alternatives are: Immediate cash purchase of the trucks for $22,500 each, and after five years sell each truck for an estimated $4,900. Lease the trucks for five years for $4,000 per year paid at...
For each question in this assignment, you should upload your output and your explanations to Canvas....
For each question in this assignment, you should upload your output and your explanations to Canvas. There are 3 questions in this assignment.    Enter the following data in SPSS and (a) produce a frequency chart, (b) produce a graph or chart appropriate for the variable, (c) explain why you chose that graph or chart that you did, (d) produce the measure of central tendency most appropriate for this variable, (e) explain why this measure of central tendency is best,...
Technical report on differences between quantum computing and current computing devices. The references taken must be...
Technical report on differences between quantum computing and current computing devices. The references taken must be 4 yrs old, not more than 4yrs old.
The deliverable for this assignment is a written report. You must address the following questions in...
The deliverable for this assignment is a written report. You must address the following questions in your analysis. Question 1: What prompted the pricing change in the case of Netflix and the debit card fee in the case of BoA? What explanation did the companies offer their customers? Do additional research as required to answer these questions. Question 2: What explains customers’ reactions to the pricing plan change announced by Netflix and the fee proposal announced by BoA? Include in...
You must provide your codes and work for full credit. 1. Feeding behavior of black bream...
You must provide your codes and work for full credit. 1. Feeding behavior of black bream fish. In Brain and Behavior Evolution (April 2000), Zoologists conducted a study of the feeding behavior of black bream fish. The zoologists recorded the number of aggressive strikes of two black bream fish feeding at the bottom of an aquarium in the 10-minute period following the addition of food. The next table lists the weekly number of strikes and age of the fish (in...
1. Your organization routinely uses scripts, but as some employees have left, there are scripts that...
1. Your organization routinely uses scripts, but as some employees have left, there are scripts that contain only command lines and no one is certain of their purpose.What steps can be taken to ensure a way for others to know the purpose of a script? a. Create text documentation of scripts and use the scriptdoc command to organize and display the documentation. b. Use the whatis command to create and save new documentation for scripts. c. Requirethatscriptwritersplacecommentlinesinsidethescriptsusingthe#symbol to begin each...
For this assignment, you will be describing hemostasis and associated disorders. Your assignment must include the...
For this assignment, you will be describing hemostasis and associated disorders. Your assignment must include the following: 1. Description of how the blood system works to stop bleeding (hemostasis). 2. Summary of the clotting cascade including a description of the intrinsic, extrinsic, and common pathways, and an overview of clotting factors. 3. Discussion of how 2 different anticoagulant medications work to stop clotting.
1- Block Codes consist of a combination of a sequence code and a mnemonic code:
  1- Block Codes consist of a combination of a sequence code and a mnemonic code: True False 2- Business process reengineering efforts sometimes fail because a- Employees will never accept change b- Management gets too involved in the process c- Management support can never overcome employee resistance d- Management is too optimistic regarding its expectations from its implementation 3- RFIDS allow firms a- Track inventory more effectively b- Eliminate the use of databases c- Reduce the costs of ERP...
You are to use your code from part A of this assignment and add to it....
You are to use your code from part A of this assignment and add to it. In this part of the project, you are to do the following: 1. In the count_voters function you are to add code to: • Count the number of votes for Trump • Count the number of votes for Biden • Count the number of females • Count the number of males • Count the number of Democrats • Count the number of Republicans •...
In your first assignment on the job, your supervisor has asked you to report on the...
In your first assignment on the job, your supervisor has asked you to report on the company’s competitors future products. You really want to succeed. What do you do? A. You could call the competitors pretending you are a college student working on project needing information B. You could ask a college friend to call the competitors and ask for the information C. You could call the competitors, but would not tell them who you really are unless if asked...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT