function a=pqfile(n) fp=fopen('wheredata.m') disp(',reading p and q of file p in a line then q in a line,') syms x p q y a for k=1:n, disp('======================problem number ='), disp(k), p = fgetl(fp); q = fgetl(fp); y=linode1(p,q), % if another program is needed such as exact1 then delete the previou line % and add y=exact1(p,q) where p=m and q=n end; fclose(fp); return %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %file wheredata.m has four problems below: x 3*x 1/x 3/x 4 -2*x tan(x) cos(x) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function y=linode1(p,q) % - revision feb 12 2004(RMM) % - Linear nonhomogeneous first order ode % - usage y=linode1(p,q) to solve y'+p y =q. % - some authors like to call the integrating factor a source or Green function. syms x u yh yp y c disp(' you are solving yprime+py=q') disp(' where p = '); disp(p) disp(' and, where q = '); disp(q) disp('Integrating Factor u= exp(int(p))') u=simplify(exp(int(p,'x'))) disp(' Homogeneous solution is yh=c/u') yh=c/u disp(' The Particular solution is yp=1/u * Int( u*q)') yp=simplify(int(u*q,'x')/u) disp(' The general solution is y = yh+yp') y=simplify(yh+yp) disp(' compare with output from the dsolve routine in matlab') dsolve('Df=p*f+q','x') return