function Problem04() % I'm writing this as a function so you can include % subfunctions below, which have been started for you. The parts for you % to fill in are marked with ??? % % To run this, in the command window type: testques4 % Step 1: Randomly initialize trainging parameters and other constants % Nothing to change here. x=randn; y=randn; % Variables to minimize E. MaxIters=100; % Max number of times to run. alpha=0.01; % Step size for gradient descent. % Step 2: Calculate the error and gradient using the subroutine below. % Please change the function below, you don't need to change the two % lines below. [E, gradE]=ErrorCalculation([x;y]); ErrToPlot(1)=E; % Step 3: Main loop for i=1:MaxIters % Gradient Descent: Finish these two expressions using the step size and gradient. x=x ??? y=y ??? %Get ready for the next iteration: % No changes here or to the end of this "for" loop. [E,gradE]=ErrorCalculation([x;y]); ErrToPlot(i+1)=E; % Check to see if we can exit: if norm(gradE)<1e-8 break end end % End of the for loop. % Visualization: % No changes needed here. figure(1) plot(ErrToPlot); fprintf('Finished on iteration %d\n',i); fprintf('Final error was %f\n',ErrToPlot(end)); fprintf('Solution is %f, %f\n',x,y); end function [E,gradE]=ErrorCalculation(vecx) x=vecx(1); y=vecx(2); % This section is where you'll want to make changes as noted: % What is the error you wrote down in 4(a). The unknowns are x, y like on the exam. E=??? % What is the gradient you wrote down in 4(b): Ex=??? Ey=?? % You don't have to change anything else; notice the vector gradE will % contain BOTH partial derivatives. gradE=[Ex;Ey]; end