Topic: | Math@UNC environment |
Post date: | May 9, 2020 |
Due date: | May 13, 2020 |
This homework is meant to familiarize yourself with basic operations within the Math@UNC environment, and is meant to be worked through in TeXmacs, a public-domain scientific editing platform. The TeXmacs website provides several tutorials. The key features of TeXmacs that motivate adoption of the platform for this course are:
Simple, efficient editing of mathematical content. The editor has a default text mode, and also a mathematics mode triggered by inserting an equation from the menu using Insert->Mathematics->(formula type), or the keyboard through key-strokes $, or Alt-Shift-$. Here is an example: the solution of the linear system with a symmetric maatrix, , can be found by gradient descent
Sessions from other mathematical packages can be inserted directly into a document. Octave is used extensively in this course, and the menu item Insert->Session->Octave leads to creation of space within the document to execute octave instructions.
octave] |
A=[1 2 3; -1 0 1; 2 1 -2]; disp(A) |
1 2 3
-1 0 1
2 1 -2
octave] |
rref(A) |
ans =
1 0 0
0 1 0
0 0 1
octave] |
inv(A) |
ans =
0.25000 -1.75000 -0.50000
0.00000 2.00000 1.00000
0.25000 -0.75000 -0.50000
octave] |
A+A |
ans =
2 4 6
-2 0 2
4 2 -4
octave] |
Documents can readily be converted to other formats: PDF, LaTeX, HTML. All course documents, including the website are produced with TeXmacs.
Write an itemized list of ingredients in your favorite dessert recipe
1/2 cup sugar
1/2 cup packed brown sugar
3 tablespoons all-purpose flour
The fundamental theorem of calculus states for . Apply this result for , , , . Write your answer inline.
A matrix is a row of column vectors, , which can be expressed in terms of vector components as
Look up the definition of a Hilbert matrix and write in the above forms, both as a row of column vectors, and as components.
A Hilbert matrix is defined with components ,
Insert an Octave session and use the hilb function to display the Hilbert matrix .
octave] |
H=hilb(4); disp(H) |
1.00000 0.50000 0.33333 0.25000
0.50000 0.33333 0.25000 0.20000
0.33333 0.25000 0.20000 0.16667
0.25000 0.20000 0.16667 0.14286
octave] |
Insert a Maxima session, and use the integrate function to compute the definite integral from Problem 2.1. When in the Maxima session, a menu of commonly used commands appears.
;;; Loading
#P"/usr/lib/ecl-16.1.3/sb-bsd-sockets.fas"
;;; Loading
#P"/usr/lib/ecl-16.1.3/sockets.fas"
;;; Loading
#P"/usr/lib/ecl-16.1.3/defsystem.fas"
;;; Loading
#P"/usr/lib/ecl-16.1.3/cmp.fas"
(%i2) |
integrate(sin(x),x,0,%pi); |
(%i3) |
Insert a Gnuplot session to plot the function .
GNUplot] |
plot sin(cos(x))+cos(sin(x)) |
GNUplot] |
Topic: Use least squares to carry out linear regression, i.e., fitting a line to data.
The following generates data by random perturbation of points on a line .
octave] |
m=500; x=(0:m-1)/m; c0=-1; c1=1; yex=c0+c1*x; y=(yex+rand(1,m)-0.5)'; |
octave] |
plot(x,yex,x,y,'.') |
octave] |
m=500 |
m = 500
octave] |
x=(0:m-1)/m; |
octave] |
x(1:4) |
ans =
0.0000000 0.0020000 0.0040000 0.0060000
octave] |
Repeat for different values of .
Define matrices , , and vector
octave] |
X=ones(m,2); X(:,2)=x(:); N=X'*X; b=X'*y; |
octave] |
X=ones(m,2); |
octave] |
size(X) |
ans =
500 2
octave] |
X(:,2)=x(:); |
octave] |
N=X'*X; |
octave] |
size(N) |
ans =
2 2
octave] |
b=X'*y; |
octave] |
size(b) |
ans =
2 1
octave] |
Repeat the above, one instruction at a time, and display the first two rows of .
Solve the system by use of the Octave backslash operator c=N\b. Display the coefficient vector , and compare to the values you chose in Question 3.1. Also compute , using ytilde as a notation.
octave] |
c=N\b; |
octave] |
size(c) |
ans =
2 1
octave] |
c |
c =
-1.0226
1.0165
octave] |
ytilde=X*c; |
octave] |
The following Octave instructions generate an Encapsulated Postscript file showing the result of the linear regression. Familiarize yourself with the syntax and purpose of each instruction. The menu item Insert->Image->Big figure has been used to insert a figure environemnt in the Answer (Figure 1). Move your cursor inside Figure 1. Use menu item Insert->Image->Link image, to link to the Encapsulated Postscript file making the image width 4in, and leaving height empty. Edit the title of your figure.
octave] |
plot(x,y,'.k',x,ytilde,'og',x,yex,'r'); title('Linear regression example'); xlabel('x'); ylabel('y,yex,ytilde'); cd /home/student/courses/MATH547ML; print hw00Fig01.eps; |
octave] |
Submission instructions. Save your work, and also export to PDF (menu File->Export->Pdf). In Sakai submit the files:
hw00.tm
any figure files you generated (e.g., that from Question 3.4)
hw00.pdf