% Plot function function [] = draw(x, x_plot, y, f, p_y, x_pred, y_pred, y_true) hold on; hold on; hold on; hold on; end % Residual calculate function function [] = res(x, p_y, y) end sum = 0; end end % Print function end % Read the data x = []; y = []; fin = fopen("data.txt", 'r'); end % Curve fitting x_pred = [12 16 21]; y_true = [28.4 28.5 29.5]; f = p(1)*x_plot + p(2); % Estimate function draw(x, x_plot, y, f, p_y, x_pred, y_pred, y_true); res(x, p_y, y); f = p(1)*x_plot.^2 + p(2)*x_plot + p(3); % Estimate function draw(x, x_plot, y, f, p_y, x_pred, y_pred, y_true); res(x, p_y, y); else f = p(1)*x_plot.^3 + p(2)*x_plot.^2 + p(3)*x_plot + p(4); % Estimate function draw(x, x_plot, y, f, p_y, x_pred, y_pred, y_true); res(x, p_y, y); end end % Fminsearch % Initial guess x0 = [10, 2]; % The square of sum of residual % fminsearch implement optimal_params = fminsearch(func, x0); % Create the estimate function with the result parameter by the fminsearch % Calculate the values with respect to the result parameter %Plot the graph draw(x, x_plot, y, optimal_func, p_y, x_pred, optimal_func_pred, y_true); %Print out value and the residual res(x, p_y, y); % Terminate section