Question: Write a code to fit the curve. Generate the training data using by adding random noise to the function sin(2 x ). Use uniformly distributed
Write a code to fit the curve. Generate the training data using by adding random noise to the function sin(2 x ). Use uniformly distributed points for the input variable, x. Since we have used only 10 points in the example it is better not to obtain x randomly.
%Define the function f = @(x) sin(2*pi*x); %Plot the function x_plot = 0:.01:1; figure, plot(x_plot, f(x_plot), 'g'), xlabel('x'), ylabel('t'),
axis square;
%Create some points N = 10; x = linspace(0, 1, N)'; %Create a random Gaussian distribution for add some noise to data std = .3; gaussian = normrnd(0, std, N, 1); %Evaluate target vector adding some noise
t = f(x) + gaussian; %Plot the target values above the function hold on, plot(x, t, 'o');
% ****** NOW FIT POLYNOMIALS OF ORDERS "M=0,...,9" % Generate the target vector for test data gaussian = normrnd(0, std, 100, 1); xx = linspace(0, 1, 100)'; t_test = f(xx) + gaussian;
Please DO not use the inbuilt MATLAB function for poly fit. You need to built the regression function on your own
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
