At Mark 22: | lrwork and liwork were removed from the interface |
None.
Open in the MATLAB editor: d02qy_example
function d02qy_example fprintf('d02qy example results\n\n'); neqf = int64(2); neqg = int64(2); vectol = true; atol = [1e-06; 1e-06]; rtol = [0.0001; 0.0001]; onestp = false; crit = true; tcrit = 10; hmax = 0; maxstp = int64(0); lrwork = 23*(1+neqf) + 14*neqg; alterg = false; sophst = true; lrwork = 23*(1+neqf) + 14*neqg; rwork = zeros(lrwork,1); liwork = 21 + 4*neqg; iwork = zeros(liwork, 1, 'int64'); % Adams method setup [statefOut, altergOut, rwork, iwork, ifail] = ... d02qw(... 'Start', neqf, vectol, atol, rtol, onestp, crit, tcrit, hmax, ... maxstp, neqg, alterg, sophst, rwork, iwork); % Integrate from t = 0 to 10 t = 0; tout = 10; y = [0; 1]; [t, y, root, rwork, iwork, ifail] = ... d02qf(... @fcn, t, y, tout, @g, neqg, rwork, iwork); % Display solution and root statistics. fprintf('Solution and root functions at t = %7.4f is:\n',t); [index, itype, events, resids, ifail] = d02qy(neqg, rwork, iwork); fprintf('\n y :'); fprintf('%10.4f',y); fprintf('\n g :'); fprintf('%10.4f',resids); fprintf('\n\nRoot Diagnostics:\n'); fprintf(' Index of event function, k : %d\n',index); fprintf(' Type of root : '); if itype==1 fprintf('simple root\n'); elseif itype==2 fprintf('root of even multiplicity\n'); elseif itype==3 fprintf('root of odd multiplicity\n'); else fprintf('root of high multiplicity or cluster?\n'); end fprintf(' event function sign change : '); if events(index)==-1 fprintf('positive to negative\n'); elseif events(index)==1 fprintf('negative to positive\n'); else events(index)==2 fprintf('no change in sign\n'); end function f = fcn(neqf, x, y) f=zeros(neqf,1); f(1)=y(2); f(2)=-y(1); function result = g(neqf, x, y, yp, k) if (k == 1) result = yp(1)+0.5; else result = y(1)-sqrt(0.5); end
d02qy example results Solution and root functions at t = 0.7854 is: y : 0.7071 0.7071 g : 1.2071 0.0000 Root Diagnostics: Index of event function, k : 2 Type of root : simple root event function sign change : negative to positive