From octave-sources-request at bevo dot che dot wisc dot edu Sun May 24 20:20:35 1998 Subject: Tests for dassl and lsode functions From: "Billinghurst, David" To: "'octave-sources at bevo dot che dot wisc dot edu'" Date: Mon, 25 May 1998 11:17:56 +1000 This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------ =_NextPart_000_01BD877A.B5650780 Content-Type: text/plain Here are a couple of tests for diffeq. +++++++++++++++++++++++++++++++++++++++++ (Mr) David Billinghurst Comalco Research and Technical Support PO Box 316, Thomastown, Vic, Australia, 3074 Phone: +61 3 9469 0642 FAX: +61 3 9462 2700 Email: David dot Billinghurst at riotinto dot com dot au <> <> <> ------ =_NextPart_000_01BD877A.B5650780 Content-Type: application/octet-stream; name="dassl-1.m" Content-Disposition: attachment; filename="dassl-1.m" # dassl-1.m # # Test dassl() function # # Author: David Billinghurst (David dot Billinghurst at riotinto dot com dot au) # Comalco Research and Technology # 20 May 1998 # # Problem # # y1' = -y2, y1(0) = 1 # y2' = y1, y2(0) = 0 # # Solution # # y1(t) = cos(t) # y2(t) = sin(t) # # x0=[1,0]; xdot0=[0,1]; t=[0:1:10]; tol=100*dassl_options("absolute tolerance"); function res = f( x, xdot, t) res = zeros(2,1); res(1) = xdot(1) + x(2); res(2) = xdot(2) - x(1); endfunction function y = soln(t) y1 = cos(t); y2 = sin(t); y = [y1;y2]'; endfunction [x,xdot] = dassl("f",x0,xdot0,t); y = soln(t); all(all( abs(x-y) < tol )) ------ =_NextPart_000_01BD877A.B5650780 Content-Type: application/octet-stream; name="dassl-2.m" Content-Disposition: attachment; filename="dassl-2.m" # dassl-2.m # # Test dassl() function # # Author: David Billinghurst (David dot Billinghurst at riotinto dot com dot au) # Comalco Research and Technology # 20 May 1998 # # Based on SLATEC quick check for DASSL by Linda Petzold # # Problem # # x1' + 10*x1 = 0, x1(0) = 1 # x1 + x2 = 1, x2(0) = 0 # # # Solution # # x1(t) = exp(-10*t) # x2(t) = 1 - x(1) # x0=[1,0]; xdot0=[-10,10]; t=[0:0.2:1]; tol=500*dassl_options("absolute tolerance"); function res = f( x, xdot, t) res = zeros(2,1); res(1) = xdot(1) + 10*x(1); res(2) = x(1) + x(2) - 1; endfunction function y = soln(t) y1 = exp(-10*t); y2 = 1 - y1; y = [y1;y2]'; endfunction [x,xdot] = dassl("f",x0,xdot0,t); y = soln(t); all(all( abs(x-y) < tol )) ------ =_NextPart_000_01BD877A.B5650780 Content-Type: application/octet-stream; name="lsode-1.m" Content-Disposition: attachment; filename="lsode-1.m" # dassl-1.m # # Test lsode() function # # Author: David Billinghurst (David dot Billinghurst at riotinto dot com dot au) # Comalco Research and Technology # 20 May 1998 # # Problem # # y1' = -y2, y1(0) = 1 # y2' = y1, y2(0) = 0 # # Solution # # y1(t) = cos(t) # y2(t) = sin(t) # x0=[1,0]; xdot0=[0,1]; t=[0:1:10]; tol=500*lsode_options("absolute tolerance"); function xdot = f( x, t) xdot = zeros(2,1); xdot(1) = -x(2); xdot(2) = x(1); endfunction function y = soln(t) y1 = cos(t); y2 = sin(t); y = [y1;y2]'; endfunction x = lsode("f",x0,t); y = soln(t); all(all( abs(x-y) < tol )) ------ =_NextPart_000_01BD877A.B5650780--