%% AAEC 6305: Dynamic Economic Optimization - Fall 2020
%% Homework 1a
%% Due: 09/03/2020 by 11:59pm
% Instructions:
% There are four problems in total each separated by a Section Break.
% Enter your code and the solutions to the problem in the provided code boxes.
% Save your file using the following structure: HW1a_lastName.mlx
% e-mail your Homework file to chenggang.wang@ttu.edu and cc matthew.looney@ttu.edu
%
%% Problem 1
%
% Plot the function, f(x)=x^2+8x+3 on the interval x \in (-10, 10) using a grid of evenly spaced points 0.01 units apart. Hints: You can built the grid using the colon operator we explored in the lab or you can look up the linspace function in MATLAB for help on creating evenly spaced points. For the power operator you need to use .^ noting the period before the ^ symbol.
% If possible, Optimize f(x) by hand and solve for the optimal value of x. Report the optimal value of x below. Use the second derivative test to determine if the critical point is a minimum or a maximum. Report the results below.

% Enter solution below
clc;clear


% The optimal value of x=
% The critical point is a

%
%% Problem 2
%
% Plot the function, f(x)=-[ (1-e^{(2x)})-10x^2+6x] on the interval x \in (-1, 1) using a grid of evenly spaced points 0.01 units apart. Hints: You can built the grid using the colon operator we explored in the lab or you can look up the linspace function in MATLAB for help on creating evenly spaced points. For the power operator you need to use .^ noting the period before the ^ symbol.
% If possible, Optimize f(x) by hand and solve for the optimal value of x. Report the optimal value of x below. Use the second derivative test to determine if the critical point is a minimum or a maximum. Report the results below.

% Enter solution below
clc;clear;


% The optimal value of x=
% The critical point is a

%
%% Problem 3
%
% Consider the matrices,
% \[A = \left[ {\begin{array}{*{20}{c}}
%   0&{ - 1}&2 \\
%   { - 2}&{ - 1}&4 \\
%   2&7&{ - 3}
% \end{array}} \right]\]
% and
% \[B = \left[ {\begin{array}{*{20}{c}}
%   { - 7}&1&1 \\
%   7&{ - 3}&{ - 2} \\
%   3&5&0
% \end{array}} \right]\]
% and the vector
% \[y = \left[ {\begin{array}{*{20}{c}}
%   3 \\
%   { - 1} \\
%   2
% \end{array}} \right]\]
% Formulate the standard matrix product C=A*B and solve the linear equation Cx=y. What are the values of C and x?
% Formulate the element-by-element matrix product C=A.*B and solve the linear equation Cx=y. What are the values of C and x?
% Hints: See the ols.m file for hints on how to solve linear equations. Also note the period before the multiplication sign. This denotes the element-by-element operator.

% Enter solutions below
clc;clear;



% standard matrix product code below


% element-by-element matrix product code below


%
%% Problem 4
%
% Using the MATLAB Normal pseudo-random number generator normrnd, simulate a hypothetical time series {y_t} governed by the structural relationship,
% y_t=5+0.05t+\epsilon_t
% for t=1960, 1961, ..., 2019, assuming that the \epsilon_t are independent and identically distributed (i.i.d.) with mean 0 and standard deviation 0.2. Using only MATLAB elementary matrix operations, regress the simulated observations of y_t on a constant and time, then plot the actual values of y and estimated trend line against time.
% Hints: See the ols.m file for hints on how to solve linear equations. Also note that we can "set the seed" using the rng function. This allows us to duplicate our random numbers. You can add multiple plots on a single window by using "plot(x1, y1, x2, y2)"

% Enter solution below
clc; clear;
rng(1234);



% Enter code for plot here
