function [x,y]=piecewise(f,g,a,b,c,n) % Usage: [y,x]=piecewise(f,g,a,b,c,n) % % this m-function generates n+1 nodes between x=a % and x=b. It then generates n+1 function evaluations % for a piecewise defined function using f(x) for % a <= x <= c and g(x) for c <= x <= b. % % input: % f - a predefined m-file called 'f1' % g - a predefined m-file called 'f2' % a - initial value of x % b - terminal value of x % c - some value between a and b where % the function changes rules % n - the number of equal subintervals between a and b % % output: % x - an array of n+1 equally spaced nodes % between a and b % y - an array of n+1 function values % delx=(b-a)/n; x=a:delx:b; y=zeros(1,n+1); z=feval(f,x(1,1)); for i=1:n+1 if x(1,i)