 LFD Book Forum Piecewise Linear Sine Function
 Register FAQ Calendar Mark Forums Read

#1
 Keith Member Join Date: Jul 2012 Posts: 16 Piecewise Linear Sine Function

Approximate the sine function in the first quadrant using a piecewise linear continuous function with two segments. Find the slope change point that minimizes the squared error difference between the piecewise linear function and its Fourier series fundamental sine component b1. The minimum is approximately:

a.) 0.014
b.) 0.018
c.) 0.023
d.) 0.027
e.) 0.030     Code:
samples = 100;
X = 0:1/samples:1;
Y = sin(X*pi/2);
xc = 0.6; % initial x value for slope change
yc = 0.8; % inital y value for slope change
% fundamental sine coefficient from Fourier series of PWL function
b1 = 8/(pi^2*(xc*(xc-1)))*(xc*sin(xc*pi/2)-yc*sin(xc*pi/2)+xc*yc-xc);
seg1 = yc/xc*X; % first linear segment samples
change = ceil(xc*samples); % index of slope change
seg1(change+1:samples+1) = 0; % remove seg1 above change point
seg2 = (1-yc)/(1-xc)*X+yc-xc*(1-yc)/(1-xc); % samples above change point
seg2(1:change) = 0; % remove seg2 up to change point
Ypwl = seg1+seg2; % combine pieces
error = (Y*b1-Ypwl).^2;
thd = sqrt(sum(error))/sqrt(sum((Y*b1).^2));
%
plot(X,Y*b1,'0',X,Ypwl,'1',X,error*100);
axis([0 1 0 1], "square");
grid on;
title('Piecewise Linear Sine Approximation');
legend('sin(x)','pwl(x)', '% error','Location', 'Northwest');
xlabel('X');ylabel('Y');
text(xc-0.04, yc+0.03, 'xc, yc');
text(1.01, b1, 'b1');
text(0.5,0.5, cstrcat('THD = ', num2str(thd)));
text(-0.03, yc-xc*(1-yc)/(1-xc),'a');

 Thread Tools Show Printable Version Email this Page Display Modes Switch to Linear Mode Switch to Hybrid Mode Threaded Mode Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home General     General Discussion of Machine Learning     Free Additional Material         Dynamic e-Chapters         Dynamic e-Appendices Course Discussions     Online LFD course         General comments on the course         Homework 1         Homework 2         Homework 3         Homework 4         Homework 5         Homework 6         Homework 7         Homework 8         The Final         Create New Homework Problems Book Feedback - Learning From Data     General comments on the book     Chapter 1 - The Learning Problem     Chapter 2 - Training versus Testing     Chapter 3 - The Linear Model     Chapter 4 - Overfitting     Chapter 5 - Three Learning Principles     e-Chapter 6 - Similarity Based Methods     e-Chapter 7 - Neural Networks     e-Chapter 8 - Support Vector Machines     e-Chapter 9 - Learning Aides     Appendix and Notation     e-Appendices

All times are GMT -7. The time now is 06:12 PM. The contents of this forum are to be used ONLY by readers of the Learning From Data book by Yaser S. Abu-Mostafa, Malik Magdon-Ismail, and Hsuan-Tien Lin, and participants in the Learning From Data MOOC by Yaser S. Abu-Mostafa. No part of these contents is to be communicated or made accessible to ANY other person or entity.