edit % Modify expression to add input arguments. % Example: % a = [1 2 3; 4 5 6]; % foo(a); ms2 ans = 6.8358 % Modify expression to add input arguments. % Example: % a = [1 2 3; 4 5 6]; % foo(a); ms2 ans = 0.4456 % Modify expression to add input arguments. % Example: % a = [1 2 3; 4 5 6]; % foo(a); ms2 ans = 0.7897 % Modify expression to add input arguments. % Example: % a = [1 2 3; 4 5 6]; % foo(a); ms2 ans = 6.8358 % Modify expression to add input arguments. % Example: % a = [1 2 3; 4 5 6]; % foo(a); ms2 ans = 8.5093e+25 options.InitialStep=0.1 options = InitialStep: 0.1000 options.name="Marco" ??? options.name="Marco" | Error: The input character is not valid in MATLAB statements or expressions. options.name='Marco' options = InitialStep: 0.1000 name: 'Marco' f=@(t,y) y; y0=1; tspan=[0,1]; [tout,yout]=rk2(f,tspan,y0); tout tout = 0 0.0500 0.1000 0.1500 0.2000 0.2500 0.3000 0.3500 0.4000 0.4500 0.5000 0.5500 0.6000 0.6500 0.7000 0.7500 0.8000 0.8500 0.9000 0.9500 1.0000 yout yout = 1.0000 1.0513 1.1051 1.1618 1.2213 1.2839 1.3497 1.4189 1.4916 1.5680 1.6484 1.7329 1.8217 1.9150 2.0132 2.1164 2.2248 2.3388 2.4587 2.5847 2.7172 yout(end)-exp(1) ans = -0.0011 abs(yout(end)-exp(1)) ans = 0.0011 [tout,yout]=rk2(f,tspan,y0); opzioni.InitialStep=0.1; [tout,yout]=rk2(f,tspan,y0,opzioni); tout' ans = Columns 1 through 4 0 0.1000 0.2000 0.3000 Columns 5 through 8 0.4000 0.5000 0.6000 0.7000 Columns 9 through 12 0.8000 0.9000 1.0000 1.0000 abs(exp(1)-yout(end)) ans = 0.0042 [tout,yout]=rk2(f,tspan,y0); abs(exp(1)-yout(end)) ans = 0.0011 opzioni.InitialStep=0.025; [tout,yout]=rk2(f,tspan,y0,opzioni); tout(2) ans = 0.0250 abs(exp(1)-yout(end)) ans = 2.7788e-04 ans*4 ans = 0.0011 opzioni.InitialStep=0.1; [tout,yout]=rk2(f,tspan,y0,opzioni); tout tout = 0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000 0.8000 0.9000 1.0000 1.0000 yout yout = 1.0000 1.1050 1.2210 1.3492 1.4909 1.6474 1.8204 2.0116 2.2228 2.4562 2.7141 2.7141 format long e tout tout = 0 1.000000000000000e-01 2.000000000000000e-01 3.000000000000000e-01 4.000000000000000e-01 5.000000000000000e-01 6.000000000000000e-01 7.000000000000000e-01 7.999999999999999e-01 8.999999999999999e-01 9.999999999999999e-01 1.000000000000000e+00 [tout,yout]=rk2(f,tspan,y0,opzioni); k = 1.000000000000000e-01 k = 1.000000000000000e-01 k = 1.000000000000000e-01 k = 1.000000000000000e-01 k = 1.000000000000000e-01 k = 1.000000000000000e-01 k = 1.000000000000000e-01 k = 1.000000000000000e-01 k = 1.000000000000000e-01 k = 1.110223024625157e-16 k = 0 [tout,yout]=rk2(f,tspan,y0,opzioni); tout tout = 0 1.000000000000000e-01 2.000000000000000e-01 3.000000000000000e-01 4.000000000000000e-01 5.000000000000000e-01 6.000000000000000e-01 7.000000000000000e-01 7.999999999999999e-01 8.999999999999999e-01 9.999999999999999e-01 t=0 t = 0 k=0.1 k = 1.000000000000000e-01 t=t+k t = 1.000000000000000e-01 k=min(k,1-t) k = 1.000000000000000e-01 t=t+k t = 2.000000000000000e-01 k=min(k,1-t) k = 1.000000000000000e-01 t=t+k t = 3.000000000000000e-01 k=min(k,1-t) k = 1.000000000000000e-01 t=t+k t = 4.000000000000000e-01 k=min(k,1-t) k = 1.000000000000000e-01 t=t+k t = 5.000000000000000e-01 k=min(k,1-t) k = 1.000000000000000e-01 t=t+k t = 6.000000000000000e-01 k=min(k,1-t) k = 1.000000000000000e-01 t=t+k t = 7.000000000000000e-01 k=min(k,1-t) k = 1.000000000000000e-01 t=t+k t = 7.999999999999999e-01 k=min(k,1-t) k = 1.000000000000000e-01 t=t+k t = 8.999999999999999e-01 k=min(k,1-t) k = 1.000000000000000e-01 t=t+k t = 9.999999999999999e-01 k=min(k,1-t) k = 1.110223024625157e-16 t=t+k t = 1 diary off