Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Numerical Methods HW: Temp Conversion, Matrix Creation, & Polynomial Eval. - Prof. Luke Ol, Assignments of Computer Science

Instructions and problems for homework set 2 in cs 257: numerical methods course. The tasks include writing functions to convert temperatures between fahrenheit and celsius, creating a tridiagonal matrix, producing output using loops and fprintf, implementing a horner function to evaluate polynomials, and processing data from a chip production file to determine yield and qualified chips at specific mhz. Each problem is accompanied by instructions and examples.

Typology: Assignments

Pre 2010

Uploaded on 03/16/2009

koofers-user-0uh
koofers-user-0uh 🇺🇸

10 documents

1 / 3

Toggle sidebar

Related documents


Partial preview of the text

Download Numerical Methods HW: Temp Conversion, Matrix Creation, & Polynomial Eval. - Prof. Luke Ol and more Assignments Computer Science in PDF only on Docsity! CS 257: Numerical Methods Spring 2006 Homework, Set 2 Due Thursday February 2, 2006 (-) Start EACH PROBLEM on a SEPARATE piece of paper (This is important since we may assign each problem to a different grader). (-) Put your NETID and HW NUMBER on top of EACH PAGE clearly, e.g. “netid: zamani hw2”. (-) Write descriptive solutions. Comment your code! (-) Include your curves/graphs (and other supporting materials) in your write-up. (-) Don’t use handwritten code (unless you want to lose points), copy-paste your code into your write-up or attach a proper print of code to your papers. (-) Please write everything in a “portrait” style (not landscape). (-) Please number problems according to numbers presented in the homework write-up that appears on the course page, NOT according to the numbers in the textbook. (-) Please type your homework or hand-write it legibly (but yet attach a print of your codes to your handwritten stuff). (1) (NMM Ch. 3 #12) Write two function m-files, FtoC and CtoF, to convert temperatures from degrees Farenheit to degrees Celsius and from degrees Celsius to degrees Farenheit. Each function should have one input parameter and one output parameter. Test your functions with >> FtoC( CtoF(100) ) >> CtoF( FtoC(32) ) >> FtoC(0:10:100) >> CtoF(0:10:100) along with any other tests you think is appropriate. (2) (NMM Ch. 3 #15) Write a function tridiag(c,d,n) where n is the dimension of a matrix and allow c and d to be vectors or scalars. The function should create the matrix D =  c1 d1 0 0 · · · 0 d1 c2 d2 0 · · · 0 0 d2 c3 d3 · · · 0 ... ... . . . . . . . . . ... 0 0 . . . . . . . . . dn−1 0 0 0 · · · dn−1 cn  if c and d are vectors, or create the matrix D =  c d 0 0 · · · 0 d c d 0 · · · 0 0 d c d · · · 0 ... ... . . . . . . . . . ... 0 0 . . . . . . . . . d 0 0 0 · · · d c  if c and d are scalars. Note that D is symmetric, i.e., D = DT . (Hint: Check the size of c and d to see if these input values are vectors or scalars.) (3) (NMM Ch. 3 #17) Write the MATLAB statements that use a loop and the fprintf function to produce the following output: (a) 1^2 = 1 2^2 = 4 3^2 = 9 4^2 = 16 5^2 = 25 (b) (0.10)^2 = 0.0100 (0.20)^2 = 0.0400 (0.30)^2 = 0.0900 (0.40)^2 = 0.1600 (0.50)^2 = 0.2500 (4) (NMM Ch. 3 #18 - #20) (I) Write a horner function that uses Horner’s rule to evaluate a polynomial of arbitrary degree. (Cf. Example 3.7 on page 113). Use the function definition function p = horner(b,x) where b is the vector of coefficients that define the polynomial. The return value p is the value of the polynomial at x. Test your function with b = [1 2 -1 0] at x = 1, 2, 3, 4, 5. (II) Extend the above function so that it returns a vector of polynomial values if the input x is a vector. (III) Extend the above function so that it can be called in two ways, viz., p = horner(b,x) and [p, pp] = horner(b,x) where p is the value of the polynomial at x and pp (p prime, p′ = dp/dx) is the value of the first derivative of p(x) evaluated at x. Make sure that your function returns p and pp as vectors if x is a vector. (5) (NMM Ch. 3 #35) Given the x vector >> x = [21 22 23 24]; and B matrix >> B = ones(3,3); write the one-line vectorized copy operation that has the same effect as the following scalar loop: k = 0; for i=2:3 for j=1:2 k = k + 1; B(i,j) = x(k); end end
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved