⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 h080503.txt

📁 (有源代码)数值分析作业,本文主要包括两个部分,第一部分是常微分方程(ODE)的三个实验题,第二部分是有关的拓展讨论,包括高阶常微分的求解和边值问题的求解(BVP).文中的算法和算例都是基于Matla
💻 TXT
📖 第 1 页 / 共 3 页
字号:
       -0.458878611459712
       -0.481423834832514
       -0.361173917672502
fprintf('%25.15f\n',y2(1:10))

        1.000000000000000
        0.953809798603462
        0.803957187302435
        0.559930144914359
        0.257785374326456
       -0.049364325033627
       -0.305157070152266
       -0.460597093943443
       -0.483166716156006
       -0.362735165423133
fprintf('%25.15f\n',x1(1:10))

        0.000000000000000
        0.200000000000000
        0.400000000000000
        0.600000000000000
        0.800000000000000
        1.000000000000000
        1.200000000000000
        1.400000000000000
        1.600000000000000
        1.800000000000000
fprintf('%25.15f\n',ye(1:10))
        1.000000000000000
        0.953810224126004
        0.803957916712868
        0.559929943470523
        0.258371014733733
       -0.048267395375700
       -0.303674050387674
       -0.458892291343109
       -0.481439689728435
       -0.361190018496207
fprintf('%+2.1e\n',ye(1:10))
fprintf('%+2.1e\n',ye(1:10))
+1.0e+000
+9.5e-001
+8.0e-001
+5.6e-001
+2.6e-001
-4.8e-002
-3.0e-001
-4.6e-001
-4.8e-001
-3.6e-001
help fprintf

 FPRINTF Write formatted data to file.
    COUNT = FPRINTF(FID,FORMAT,A,...) formats the data in the real
    part of matrix A (and in any additional matrix arguments), under
    control of the specified FORMAT string, and writes it to the file
    associated with file identifier FID.  COUNT is the number of bytes
    successfully written. FID is an integer file identifier obtained
    from FOPEN. It can also be 1 for standard output (the screen) or 2
    for standard error. If FID is omitted, output goes to the screen.
    
    FORMAT is a string containing C language conversion specifications.
    Conversion specifications involve the character %, optional flags,
    optional width and precision fields, optional subtype specifier, and
    conversion characters d, i, o, u, x, X, f, e, E, g, G, c, and s.
    See the Language Reference Guide or a C manual for complete details.
 
    The special formats \n,\r,\t,\b,\f can be used to produce linefeed,
    carriage return, tab, backspace, and formfeed characters respectively.
    Use \\ to produce a backslash character and %% to produce the percent
    character.
 
    FPRINTF behaves like ANSI C with certain exceptions and extensions. 
    These include:
    1. Only the real part of each parameter is processed.
    2. The following non-standard subtype specifiers are supported for
       conversion characters o, u, x, and X.
       t    - The underlying C datatype is a float rather than an
              unsigned integer.
       b    - The underlying C datatype is a double rather than an
              unsigned integer.
       For example, to print out in hex a double value use a format like
       '%bx'.
    3. FPRINTF is "vectorized" for the case when A is nonscalar. The
       format string is recycled through the elements of A (columnwise)
       until all the elements are used up. It is then recycled in a similar
       manner through any additional matrix arguments.
    
    For example, the statements
 
        x = 0:.1:1; y = [x; exp(x)];
        fid = fopen('exp.txt','w');
        fprintf(fid,'%6.2f  %12.8f\n',y);
        fclose(fid);
 
    create a text file containing a short table of the exponential function:
 
        0.00    1.00000000
        0.10    1.10517092
             ...
        1.00    2.71828183
 
    See also FSCANF, SPRINTF, FWRITE, DIARY, SAVE, INPUT.

err1=y1-ye;

err2=y2-ye;

fprintf('%+2.1e\n',err1(1:10))

fprintf('%+2.1e\n',err2(1:10))
err1=y1-ye;

err2=y2-ye;

fprintf('%+2.1e\n',err1(1:10))

+0.0e+000
-4.3e-007
-7.3e-007
+2.0e-007
+2.6e-006
+6.2e-006
+1.0e-005
+1.4e-005
+1.6e-005
+1.6e-005
fprintf('%+2.1e\n',err2(1:10))
+0.0e+000
-4.3e-007
-7.3e-007
+2.0e-007
-5.9e-004
-1.1e-003
-1.5e-003
-1.7e-003
-1.7e-003
-1.5e-003
fprintf('%+2.1e\n',err1(1:10))
fprintf('%+2.1e\n',err1(1:10))
+0.0e+000
-4.3e-007
-7.3e-007
+2.0e-007
+2.6e-006
+6.2e-006
+1.0e-005
+1.4e-005
+1.6e-005
+1.6e-005
fprintf('%+2.1e\n',err2(1:10))
fprintf('%+2.1e\n',err2(1:10))
+0.0e+000
-4.3e-007
-7.3e-007
+2.0e-007
-5.9e-004
-1.1e-003
-1.5e-003
-1.7e-003
-1.7e-003
-1.5e-003
[x1,y1]=rk_wjl('funtest3',0,2,1,0.1);

[x2,y2]=adams_wjl('funtest3',0,2,1,0.1);

ye=feval('exact53',x1);

fprintf('%25.15f\n',y1(1:10))

fprintf('%25.15f\n',y2(1:10))

fprintf('%25.15f\n',x1(1:10))

fprintf('%25.15f\n',ye(1:10))



err1=y1-ye;

err2=y2-ye;

fprintf('%+2.1e\n',err1(1:10))

fprintf('%+2.1e\n',err2(1:10))
[x1,y1]=rk_wjl('funtest3',0,2,1,0.1);

[x2,y2]=adams_wjl('funtest3',0,2,1,0.1);

ye=feval('exact53',x1);

fprintf('%25.15f\n',y1(1:10))

        1.000000000000000
        0.989114945734689
        0.953810207163844
        0.892009234874488
        0.803957909846734
        0.691934997689581
        0.559930026601258
        0.413294102786211
        0.258371272387045
        0.102119698111956
fprintf('%25.15f\n',y2(1:10))

        1.000000000000000
        0.989114945734689
        0.953810207163844
        0.892009234874488
        0.803946526054440
        0.691912143058377
        0.559895701637239
        0.413248584770018
        0.258315189239600
        0.102054027108314
fprintf('%25.15f\n',x1(1:10))

        0.000000000000000
        0.100000000000000
        0.200000000000000
        0.300000000000000
        0.400000000000000
        0.500000000000000
        0.600000000000000
        0.700000000000000
        0.800000000000000
        0.900000000000000
fprintf('%25.15f\n',ye(1:10))

        1.000000000000000
        0.989114952021601
        0.953810224126004
        0.892009254771033
        0.803957916712868
        0.691934970796298
        0.559929943470523
        0.413293941758031
        0.258371014733733
        0.102119329696798


err1=y1-ye;

err2=y2-ye;

fprintf('%+2.1e\n',err1(1:10))

+0.0e+000
-6.3e-009
-1.7e-008
-2.0e-008
-6.9e-009
+2.7e-008
+8.3e-008
+1.6e-007
+2.6e-007
+3.7e-007
fprintf('%+2.1e\n',err2(1:10))
+0.0e+000
-6.3e-009
-1.7e-008
-2.0e-008
-1.1e-005
-2.3e-005
-3.4e-005
-4.5e-005
-5.6e-005
-6.5e-005
plot(x1,err1,x1,err2)
plot(x1,err1,x1,err2)
[x1,y1]=rk_wjl('funtest3',0,2,1,0.01);

[x2,y2]=adams_wjl('funtest3',0,2,1,0.01);

ye=feval('exact53',x1);

fprintf('%25.15f\n',y1(1:10))

fprintf('%25.15f\n',y2(1:10))

fprintf('%25.15f\n',x1(1:10))

fprintf('%25.15f\n',ye(1:10))



err1=y1-ye;

err2=y2-ye;

fprintf('%+2.1e\n',err1(1:10))

fprintf('%+2.1e\n',err2(1:10))

plot(x1,err1,x1,err2)
[x1,y1]=rk_wjl('funtest3',0,2,1,0.01);

[x2,y2]=adams_wjl('funtest3',0,2,1,0.01);

ye=feval('exact53',x1);

fprintf('%25.15f\n',y1(1:10))

        1.000000000000000
        0.999899011649947
        0.999592186130278
        0.999073940915349
        0.998338969405180
        0.997382238839153
        0.996198988174600
        0.994784725929957
        0.993135227992230
        0.991246535388494
fprintf('%25.15f\n',y2(1:10))

        1.000000000000000
        0.999899011649947
        0.999592186130278
        0.999073940915349
        0.998338969347264
        0.997382238723025
        0.996198987999840
        0.994784725696165
        0.993135227698999
        0.991246535035416
fprintf('%25.15f\n',x1(1:10))

        0.000000000000000
        0.010000000000000
        0.020000000000000
        0.030000000000000
        0.040000000000000
        0.050000000000000
        0.060000000000000
        0.070000000000000
        0.080000000000000
        0.090000000000000
fprintf('%25.15f\n',ye(1:10))

        1.000000000000000
        0.999899011649953
        0.999592186130301
        0.999073940915398
        0.998338969405263
        0.997382238839277
        0.996198988174770
        0.994784725930176
        0.993135227992501
        0.991246535388818


err1=y1-ye;

err2=y2-ye;

fprintf('%+2.1e\n',err1(1:10))

+0.0e+000
-5.9e-015
-2.3e-014
-4.9e-014
-8.3e-014
-1.2e-013
-1.7e-013
-2.2e-013
-2.7e-013
-3.2e-013
fprintf('%+2.1e\n',err2(1:10))

+0.0e+000
-5.9e-015
-2.3e-014
-4.9e-014
-5.8e-011
-1.2e-010
-1.7e-010
-2.3e-010
-2.9e-010
-3.5e-010
plot(x1,err1,x1,err2)
plot(x1,err1,x1,err2)
plot(x1,err1,x1,err2)
disp(which('na53test'));
e:\matlabtemp\na53test.m
clear 'e:\matlabtemp\na53test.m'
disp(which('na53test'));
e:\matlabtemp\na53test.m
clear 'e:\matlabtemp\na53test.m'


[x1,y1]=rk_wjl('funtest3',0,10,1,0.1);

[x2,y2]=adams_wjl('funtest3',0,10,1,0.1);

ye=feval('exact53',x1);

fprintf('%25.15f\n',y1(1:10))

fprintf('%25.15f\n',y2(1:10))

fprintf('%25.15f\n',x1(1:10))

fprintf('%25.15f\n',ye(1:10))



err1=y1-ye;

err2=y2-ye;

fprintf('%+2.1e\n',err1(1:10))

fprintf('%+2.1e\n',err2(1:10))

plot(x1,err1,x1,err2)


[x1,y1]=rk_wjl('funtest3',0,10,1,0.1);

[x2,y2]=adams_wjl('funtest3',0,10,1,0.1);

ye=feval('exact53',x1);

fprintf('%25.15f\n',y1(1:10))

        1.000000000000000
        0.989114945734689
        0.953810207163844
        0.892009234874488
        0.803957909846734
        0.691934997689581
        0.559930026601258
        0.413294102786211
        0.258371272387045
        0.102119698111956
fprintf('%25.15f\n',y2(1:10))

        1.000000000000000
        0.989114945734689
        0.953810207163844
        0.892009234874488
        0.803946526054440
        0.691912143058377
        0.559895701637239
        0.413248584770018
        0.258315189239600
        0.102054027108314
fprintf('%25.15f\n',x1(1:10))

        0.000000000000000
        0.100000000000000
        0.200000000000000
        0.300000000000000
        0.400000000000000
        0.500000000000000
        0.600000000000000
        0.700000000000000
        0.800000000000000
        0.900000000000000
fprintf('%25.15f\n',ye(1:10))

        1.000000000000000
        0.989114952021601
        0.953810224126004
        0.892009254771033
        0.803957916712868
        0.691934970796298
        0.559929943470523
        0.413293941758031
        0.258371014733733
        0.102119329696798


err1=y1-ye;

err2=y2-ye;

fprintf('%+2.1e\n',err1(1:10))

+0.0e+000
-6.3e-009
-1.7e-008
-2.0e-008
-6.9e-009
+2.7e-008
+8.3e-008
+1.6e-007
+2.6e-007
+3.7e-007
fprintf('%+2.1e\n',err2(1:10))

+0.0e+000
-6.3e-009
-1.7e-008
-2.0e-008
-1.1e-005
-2.3e-005
-3.4e-005
-4.5e-005
-5.6e-005
-6.5e-005
plot(x1,err1,x1,err2)
dbstack
;
disp(which('adams_wjl'));
e:\matlabtemp\adams_wjl.m
mdbstatus 'e:\matlabtemp\adams_wjl.m'
dbstack
;
disp(which('rk_wjl'));
e:\matlabtemp\rk_wjl.m
mdbstatus 'e:\matlabtemp\rk_wjl.m'
dbstack
;
disp(which('adams_wjl1'));
e:\matlabtemp\adams_wjl1.m
clear 'e:\matlabtemp\adams_wjl1.m'
[x1,y1]=rk_wjl('funtest3',0,10,1,0.1);

[x2,y2]=adams_wjl1('funtest3',0,10,1,0.1);

ye=feval('exact53',x1);

fprintf('%25.15f\n',y1(1:10))

fprintf('%25.15f\n',y2(1:10))

fprintf('%25.15f\n',x1(1:10))

fprintf('%25.15f\n',ye(1:10))



err1=y1-ye;

err2=y2-ye;

fprintf('%+2.1e\n',err1(1:10))

fprintf('%+2.1e\n',err2(1:10))

plot(x1,err1,x1,err2)
[x1,y1]=rk_wjl('funtest3',0,10,1,0.1);

[x2,y2]=adams_wjl1('funtest3',0,10,1,0.1);

???  Index exceeds matrix dimensions.

Error in ==> e:\matlabtemp\adams_wjl1.m
On line 41  ==>    f(i+1) = feval(odefile,x(i+1),y(i+1),varargin{:});

cc
disp(which('adams_wjl1'));
e:\matlabtemp\adams_wjl1.m
clear 'e:\matlabtemp\adams_wjl1.m'
disp(which('adams_wjl1'));
e:\matlabtemp\adams_wjl1.m
dbstop at 41 in 'e:\matlabtemp\adams_wjl1.m'
disp(which('adams_wjl1'));
e:\matlabtemp\adams_wjl1.m
clear 'e:\matlabtemp\adams_wjl1.m'
[x2,y2]=adams_wjl1('funtest3',0,10,1,0.1);
[x2,y2]=adams_wjl1('funtest3',0,10,1,0.1);
???  Index exceeds matrix dimensions.

Error in ==> e:\matlabtemp\adams_wjl1.m
On line 41  ==>    f(i+1) = feval(odefile,x(i+1),y(i+1),varargin{:});

disp(which('adams_wjl1'));
e:\matlabtemp\adams_wjl1.m
dbstop at 41 in 'e:\matlabtemp\adams_wjl1.m'
disp(which('adams_wjl1'));
e:\matlabtemp\adams_wjl1.m
clear 'e:\matlabtemp\adams_wjl1.m'
disp(which('adams_wjl1'));
e:\matlabtemp\adams_wjl1.m
dbstop at 41 in 'e:\matlabtemp\adams_wjl1.m'
[x2,y2]=adams_wjl1('funtest3',0,10,1,0.1);
dbstack
> In e:\matlabtemp\adams_wjl1.m at line 41
eval( 'if exist(''ynp'',''var''), mauifunc(ynp), end', '');
     0

dbstep
???  Index exceeds matrix dimensions.

Error in ==> e:\matlabtemp\adams_wjl1.m
On line 41  ==>    f(i+1) = feval(odefile,x(i+1),y(i+1),varargin{:});


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -