In this function how can I replace "for" by "parfor". I get this error when I do so:
"The parfor loop cannot run due to the way variable 'y' is defined."
function [x,y] = Euler(ODEfile,xi,xf,h,yi,varargin)% EULER Solves a set of ordinary differential equations by
% the modified Euler (predictor-corrector) method.
%
% [X,Y]=EULER('F',XI,XF,H,YI) solves a set of ordinary
% differential equations by the modified Euler (the Euler
% predictor-corrector) method, from XI to XF.
% The equations are given in the M-file F.M.
% H is the length of interval and
% YI is the vector of initial values of the dependent variable at XI.
%% [X,Yl=EULER('F', XI, XF,H,YI, P1,P2,. . . ) allows for additional
% arguments which are passed to the function F(X,Pl,P2,. . . ) .
if (isempty (h) || h == 0) h = linspace(xi,xf);endyi = (yi (:).')' ;x = [xi:h:xf];if x(end) ~= xf x(end+1) = xf;endd = diff (x);y(:,1) = yi;% Solution
for i = 1:length(x)-1 % Predictor
y(:,i+1)=y(:,i) + d(i) * feval(ODEfile,x(i), y(:,i), varargin{:}); % Corrector
y(:,i+1) =y (:,i) + d(i) * feval(ODEfile, x(i+1), y(:,i+1), varargin{:}) ;end
Best Answer