w=fminsearch (@q1,[2;-2;26]) x=[1,2,3,4,5,6,7,8,9,10]; y=[0,2,6,10,12,10,7,5,1,0]; plot(x,y) N=1 for r=min(x):1:max(x) if x(N) < 5 y3(N)=10*x(N)*w(1) +w(2); elseif x(N) >= 5 y3(N)=-10*x(N)*w(1) +w(3); endif N=N+1; endfor hold on plot(x,y3)