0% found this document useful (0 votes)
89 views4 pages

1.1 Homework Set No. 1: Problem 1

This homework document contains 5 problems related to binary and decimal number conversion, computing functions accurately for large values, using Matlab to find interpolating polynomials and plot functions, and studying the effect of computer arithmetic on evaluating the quadratic formula and improving the method. The problems provide exercises in binary, decimal, scientific notation, roots of polynomials, matrix equations, plotting, and writing Matlab functions.

Uploaded by

kelbmuts
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
89 views4 pages

1.1 Homework Set No. 1: Problem 1

This homework document contains 5 problems related to binary and decimal number conversion, computing functions accurately for large values, using Matlab to find interpolating polynomials and plot functions, and studying the effect of computer arithmetic on evaluating the quadratic formula and improving the method. The problems provide exercises in binary, decimal, scientific notation, roots of polynomials, matrix equations, plotting, and writing Matlab functions.

Uploaded by

kelbmuts
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1.1. HOMEWORK SET NO.

1 1

1.1 Homework set No. 1

Problem 1

(A). Convert the binary numbers to decimal.


i). (110111001.101011101)2 ii). (1001100101.01101)2
(B). Convert the decimal numbers to binary. Keep 10 fractional points.
i). (100.01)10 (ii). (64.625)10
(C). Write (64.625)10 into normalized scientific notation in binary. Then determine
how it would look like in a 32-bit computer, using a single-precision floating point
representation.

Problem 2:

For some values of x, the function f (x) = x2 + 1 − x cannot be accurately computed
by using this formula. Explain and find a way around the difficulty.

Problem 3:
√ √
How can the values of the function f (x) = x+2− x be computed accurately when
x is large?

Problem 4: Matlab exercises:

The goal of this exercise is to get started with Matlab. You will go through:

• Matrix, vector, solutions of systems of linear equations;

• simple plots;

• Use of Matlab’s own help functions.

The target problem: Find the interpolating polynomial

p3 (x) = a3 x3 + a2 x2 + a1 x + a0 (1.1)

that interpolates the following data points:

xi 0 5 10 15
(1.2)
yi 3 8 −2 9
2

Preparations:

a) Show that the coefficients to the interpolating polynomial (1) can be found by
solving     
1 0 0 0 a0 3
1 5 25 125  a1   8 
   =   (1.3)
1 10 100 1000 a2  −2
1 15 225 3375 a3 9

b) Read Ch. 1 and 2 in “A Practical Introduction to Matlab” by Gockenbach (you


find it at the web-page of the course).

How do you do it:

Introduction

Find a computer with Matlab installed in it. Start Matlab, by either click on the
appropriate icon(Windows), or by typing in matlab (unix or linux). You should get a
command window on the screen.
Go through the examples in Gockenbach’s notes.

Linear equations
Solve the system of linear equations (3).
The interpolating polynomial should be

p3 (x) = 0.048x3 − 1.02x2 + 4.9x + 3.

Simple plots
Plot the interpolating points and the interpolating polynomial. In addition to the func-
tion plot try also:
grid on/off: add or remove a grid on the plot.
xlabel(’text’): put text under x-axis.
ylabel(’text’): put text next to y-axis.
title(’text’): put text above the plot.

Help!
As we will see later, Matlab has many build-in numerical functions. One among them
is a function that does polynomial interpolation. But what is the name, and how to use
it? Here we will see how we could use lookfor to find the function, and help to get a
description on how to use it.
lookfor keyword: Look after the “keyword” among Matlab functions.
1.1. HOMEWORK SET NO. 1 3

Try for example:


lookfor polynomial

and see what you can find.


Suppose you get polyfit and polyval as your candidates. For more information on
them you can type: help function,
and in our case you type:
help polyfit,
which gives:

POLYFIT Fit polynomial to data.


POLYFIT(X,Y,N) finds the coefficients of a polynomial P(X) of
degree N that fits the data, P(X(I))~=Y(I), in a least-squares sense.
...

Here X is a vector with the x-values, and Y is a vector with y values from the table in
(2) in our example. N is the order of the polynomial, and in our case we use 3. The
function returns a vector with the coefficients of the polynomial.

Helpdesk

It might happen that you think the information coming from help is a bit creepy. It
would be nice to have some examples or such things. Fortunately Matlab has a web-
based online manual. You can start it by type in
helpdesk
and a web reader window will pop up, with a start-page for Matlab. Go to Matlab
function polyfit, and you get more self-explaining information. You should also check
the function polyval.
Now, use these functions polyfit and polyval to compute and plot the interpolating
polynomial for table (2).

Problem 5: A study of loss of significant digits.

In this problem we will consider the effect of computer arithmetic on the evaluation of
the quadratic formula

−b ± b2 − 4ac
r1,2 =
2a
for the roots of p(x) = ax2 + bx + c.
4

a. Write a Matlab function, call it quadroots, that takes a, b, c as input and returns
the two roots as output,like

function [r1, r2] = quadroots(a,b,c)

Use the formula above for the computation. Run it on a few test problems to make sure
that it works before you go ahead with the following problems.

b. Test quadroots in this way for the following polynomials:

• 2x2 + 6x − 3

• x2 − 14x + 49

• 3x2 − 123454321x + 2

What do you get? Why are the results so bad for the last polynomial?

c. The product of the roots of ax2 + bx + c is of course c/a. Use this fact to improve
your program, call it smartquadroots, to see if you get better results. (Matlab has a
command roots(p) which returns the roots of the polynomial with coefficients in p.
roots is smarter than quadroots and will give accurate answers here. You can use it
to check your results from smartquadroots function.)
What to hand in: Hand in two Matlab function m-files (quadroots.m and smartquad-
roots.m), the results you get, and your comments.

You might also like