Montesdeoca Joshua Euler RK MatLab ED
Montesdeoca Joshua Euler RK MatLab ED
Montesdeoca Joshua Euler RK MatLab ED
Ejercicios 2.6
En los problemas 1 y 2 use el método de Euler para obtener una aproximación a cuatro decimales del
valor indicado, ejecute a mano la ecuación de recursión (3), usando primero h = 0.1 y después usando
h = 0.05.
resp1 = 6×2
1.0000 5.0000
1.1000 3.8000
1.2000 2.9800
1.3000 2.4260
1.4000 2.0582
1.5000 1.8207
plot(x1,y1,'r','linewidth',2)
hold on, grid on, grid minor
plot(x1,solex,'b','linewidth',2)
legend('Euler','Sol Exacta')
1
clear, close, clc
[x2,y2] = euler('ejercicio01',1,1.5,0.05,5);
solex=(2*x2)./3 + (38*exp(-3*x2).*exp(3))/9 + 1/9;
% eabs=solex-y2;
% erel=eabs./solex;
resp2=[x2,y2] %[,solex,eabs,erel]
resp2 = 11×2
1.0000 5.0000
1.0500 4.4000
1.1000 3.8950
1.1500 3.4708
1.2000 3.1151
1.2500 2.8179
1.3000 2.5702
1.3500 2.3647
1.4000 2.1950
1.4500 2.0557
plot(x2,y2,'r','linewidth',2)
hold on, grid on, grid minor
plot(x2,solex,'b','linewidth',2)
legend('Euler','Sol Exacta')
2
Ejercicio 2: y' = x + y^2, y(0) = 0; y(0.2)
resp1 = 3×2
0 0
0.1000 0
0.2000 0.0100
plot(x1,y1,'r','linewidth',2)
hold on, grid on, grid minor
plot(x1,solex,'b','linewidth',2)
legend('Euler','Sol Exacta')
3
clear, close, clc
[x2,y2] = euler('ejercicio02',0,0.2,0.05,0);
solex=x2.^(1/2).*tan(y2.*x2.^(1/2));
% eabs=solex-y2;
% erel=eabs./solex;
resp1=[x2,y2] %[,solex,eabs,erel]
resp1 = 5×2
0 0
0.0500 0
0.1000 0.0025
0.1500 0.0075
0.2000 0.0150
plot(x2,y2,'r','linewidth',2)
hold on, grid on, grid minor
plot(x2,solex,'b','linewidth',2)
legend('Euler','Sol Exacta')
4
En los problemas 3 y 4 use el método de Euler para obtener una aproximación a cuatro decimales del
valor indicado. Primero utilice h = 0.1 y después utilice h = 0.05. Determine una solución explícita para
cada problema con valores iniciales y después construya tablas similares a las tablas 2.3 y 2.4.
resp1 = 11×5
0 1.0000 2.7183 1.7183 0.6321
0.1000 1.1000 3.0042 1.9042 0.6338
0.2000 1.2100 3.3535 2.1435 0.6392
0.3000 1.3310 3.7848 2.4538 0.6483
0.4000 1.4641 4.3237 2.8596 0.6614
0.5000 1.6105 5.0054 3.3949 0.6782
0.6000 1.7716 5.8800 4.1085 0.6987
0.7000 1.9487 7.0197 5.0710 0.7224
0.8000 2.1436 8.5300 6.3864 0.7487
0.9000 2.3579 10.5692 8.2113 0.7769
plot(x1,y1,'r','linewidth',2)
hold on, grid on, grid minor
5
plot(x1,solex,'b','linewidth',2)
legend('Euler','Sol Exacta')
resp1 = 21×5
0 1.0000 2.7183 1.7183 0.6321
0.0500 1.0500 2.8577 1.8077 0.6326
0.1000 1.1025 3.0117 1.9092 0.6339
0.1500 1.1576 3.1824 2.0247 0.6362
0.2000 1.2155 3.3720 2.1565 0.6395
0.2500 1.2763 3.5833 2.3070 0.6438
0.3000 1.3401 3.8194 2.4793 0.6491
0.3500 1.4071 4.0841 2.6770 0.6555
0.4000 1.4775 4.3818 2.9043 0.6628
0.4500 1.5513 4.7177 3.1664 0.6712
plot(x2,y2,'r','linewidth',2)
hold on, grid on, grid minor
plot(x2,solex,'b','linewidth',2)
legend('Euler','Sol Exacta')
6
Ejercicio 4: y' = 2xy, y(1) = 1; y(1.5)
resp1 = 11×5
0 1.0000 1.0000 0 0
0.1000 1.0000 1.0000 0 0
0.2000 1.0200 1.0080 -0.0120 -0.0119
0.3000 1.0608 1.0372 -0.0236 -0.0228
0.4000 1.1244 1.1047 -0.0198 -0.0179
0.5000 1.2144 1.2391 0.0247 0.0199
0.6000 1.3358 1.4963 0.1605 0.1073
0.7000 1.4961 2.0029 0.5068 0.2530
0.8000 1.7056 3.0925 1.3869 0.4485
0.9000 1.9785 5.8200 3.8415 0.6601
plot(x1,y1,'r','linewidth',2)
hold on, grid on, grid minor
plot(x1,solex,'b','linewidth',2)
legend('Euler','Sol Exacta')
7
clear, close, clc
[x2,y2] = euler('ejercicio04',0,1.0,0.05,1);
solex=exp(-2.*x2).*exp(2.*y2.*x2);
eabs=solex-y2;
erel=eabs./solex;
resp1=[x2,y2,solex,eabs,erel]
resp1 = 21×5
0 1.0000 1.0000 0 0
0.0500 1.0000 1.0000 0 0
0.1000 1.0050 1.0010 -0.0040 -0.0040
0.1500 1.0150 1.0045 -0.0105 -0.0105
0.2000 1.0303 1.0122 -0.0181 -0.0179
0.2500 1.0509 1.0258 -0.0251 -0.0245
0.3000 1.0772 1.0474 -0.0298 -0.0284
0.3500 1.1095 1.0796 -0.0298 -0.0276
0.4000 1.1483 1.1260 -0.0223 -0.0198
0.4500 1.1942 1.1910 -0.0032 -0.0027
plot(x2,y2,'r','linewidth',2)
hold on, grid on, grid minor
plot(x2,solex,'b','linewidth',2)
legend('Euler','Sol Exacta')
8
En los problemas 5 a 10 use un solucionador numérico y el método de Euler para obtener una
aproximación a cuatro decimales del valor indicado. Primero utilice h = 0.1 y después utilice h = 0.05.
resp1 = 6×5
0 0 0 0 NaN
0.1000 0.1000 0.0953 -0.0047 -0.0492
0.2000 0.1905 0.1823 -0.0082 -0.0448
0.3000 0.2731 0.2624 -0.0108 -0.0411
0.4000 0.3492 0.3365 -0.0128 -0.0379
0.5000 0.4198 0.4055 -0.0143 -0.0353
plot(x1,y1,'r','linewidth',2)
hold on, grid on, grid minor
plot(x1,solex,'b','linewidth',2)
[x2,y2]=RK2('ejercicio05',0,0.5,0.1,0)
x2 = 1×6
0 0.1000 0.2000 0.3000 0.4000 0.5000
y2 = 6×1
0
9
0.0952
0.1822
0.2622
0.3363
0.4053
plot(x2,y2,'g','linewidth',2)
legend('Euler','Sol Exacta','RK2','Location','northwest')
resp2 = 11×5
0 0 0 0 NaN
0.0500 0.0500 0.0488 -0.0012 -0.0248
0.1000 0.0976 0.0953 -0.0023 -0.0236
0.1500 0.1429 0.1398 -0.0032 -0.0226
0.2000 0.1863 0.1823 -0.0039 -0.0216
0.2500 0.2278 0.2231 -0.0046 -0.0207
0.3000 0.2676 0.2624 -0.0052 -0.0199
0.3500 0.3058 0.3001 -0.0057 -0.0191
0.4000 0.3427 0.3365 -0.0062 -0.0184
0.4500 0.3782 0.3716 -0.0066 -0.0177
10
plot(x3,y3,'r','linewidth',2)
hold on, grid on, grid minor
plot(x3,solex,'b','linewidth',2)
[x4,y4]=RK2('ejercicio05',0,0.5,0.05,0)
x4 = 1×11
0 0.0500 0.1000 0.1500 0.2000 0.2500 0.3000 0.3500
y4 = 11×1
0
0.0488
0.0953
0.1397
0.1823
0.2231
0.2623
0.3001
0.3364
0.3715
plot(x4,y4,'g','linewidth',2)
legend('Euler','Sol Exacta','RK2','Location','northwest')
11
erel=eabs./solex;
resp1=[x1,y1,solex,eabs,erel]
resp1 = 6×5
0 1.0000 0 -1.0000 -Inf
0.1000 1.1000 -9.6789 -10.7789 1.1136
0.2000 1.2220 -4.2518 -5.4738 1.2874
0.3000 1.3753 -2.4643 -3.8396 1.5581
0.4000 1.5735 -1.5738 -3.1473 1.9998
0.5000 1.8371 -1.0223 -2.8594 2.7970
plot(x1,y1,'r','linewidth',2)
hold on, grid on, grid minor
plot(x1,solex,'b','linewidth',2)
[x2,y2]=RK2('ejercicio06',0,0.5,0.1,1)
x2 = 1×6
0 0.1000 0.2000 0.3000 0.4000 0.5000
y2 = 6×1
1.0000
1.1110
1.2515
1.4361
1.6880
2.0488
plot(x2,y2,'g','linewidth',2)
legend('Euler','Sol Exacta','RK2','Location','northwest')
12
solex=x3.*tan(atan(1./x3) + y3.*x3);
eabs=solex-y3;
erel=eabs./solex;
resp2=[x3,y3,solex,eabs,erel]
resp2 = 11×5
0 1.0000 0 -1.0000 -Inf
0.0500 1.0500 -19.6726 -20.7226 1.0534
0.1000 1.1053 -9.2108 -10.3161 1.1200
0.1500 1.1668 -5.7383 -6.9051 1.2033
0.2000 1.2360 -4.0119 -5.2480 1.3081
0.2500 1.3144 -2.9825 -4.2970 1.4407
0.3000 1.4039 -2.2997 -3.7036 1.6105
0.3500 1.5070 -1.8124 -3.3194 1.8315
0.4000 1.6267 -1.4444 -3.0711 2.1261
0.4500 1.7670 -1.1524 -2.9194 2.5332
plot(x3,y3,'r','linewidth',2)
hold on, grid on, grid minor
plot(x3,solex,'b','linewidth',2)
[x4,y4]=RK2('ejercicio06',0,0.5,0.05,1)
x4 = 1×11
0 0.0500 0.1000 0.1500 0.2000 0.2500 0.3000 0.3500
y4 = 11×1
1.0000
1.0526
1.1113
1.1775
1.2526
1.3388
1.4387
1.5556
1.6939
1.8598
plot(x4,y4,'g','linewidth',2)
legend('Euler','Sol Exacta','RK2','Location','northwest')
13
Ejercicio 7: y' = (x - y)^2, y(0) = 0.5; y(0.5)
resp1 = 6×5
0 0.5000 0.5000 -0.0000 -0.0000
0.1000 0.5250 0.5213 -0.0037 -0.0070
0.2000 0.5431 0.5358 -0.0073 -0.0136
0.3000 0.5548 0.5443 -0.0106 -0.0194
0.4000 0.5613 0.5482 -0.0131 -0.0239
0.5000 0.5639 0.5493 -0.0147 -0.0267
plot(x1,y1,'r','linewidth',2)
hold on, grid on, grid minor
plot(x1,solex,'b','linewidth',2)
[x2,y2]=RK2('ejercicio07',0,0.5,0.1,0.5)
x2 = 1×6
0 0.1000 0.2000 0.3000 0.4000 0.5000
y2 = 6×1
0.5000
0.5215
0.5362
0.5449
14
0.5490
0.5503
plot(x2,y2,'y','linewidth',2)
legend('Euler','Sol Exacta','RK2','Location','northwest')
resp1 = 11×5
0 0.5000 0.5000 -0.0000 -0.0000
0.0500 0.5125 0.5116 -0.0009 -0.0018
0.1000 0.5232 0.5213 -0.0019 -0.0036
0.1500 0.5322 0.5294 -0.0028 -0.0053
0.2000 0.5395 0.5358 -0.0037 -0.0069
0.2500 0.5452 0.5407 -0.0045 -0.0084
0.3000 0.5496 0.5443 -0.0053 -0.0097
0.3500 0.5527 0.5467 -0.0060 -0.0109
0.4000 0.5547 0.5482 -0.0065 -0.0119
0.4500 0.5559 0.5490 -0.0070 -0.0127
plot(x3,y3,'r','linewidth',2)
hold on, grid on, grid minor
plot(x3,solex,'b','linewidth',2)
15
[x4,y4]=RK2('ejercicio07',0,0.5,0.05,0.5)
x4 = 1×11
0 0.0500 0.1000 0.1500 0.2000 0.2500 0.3000 0.3500
y4 = 11×1
0.5000
0.5116
0.5214
0.5294
0.5359
0.5408
0.5444
0.5469
0.5484
0.5492
plot(x4,y4,'y','linewidth',2)
legend('Euler','Sol Exacta','RK2','Location','northwest')
16
resp1 = 6×5
0 1.0000 1.0000 0 0
0.1000 1.0500 1.0565 0.0065 0.0062
0.2000 1.1130 1.1275 0.0145 0.0129
0.3000 1.1909 1.2153 0.0244 0.0201
0.4000 1.2862 1.3231 0.0369 0.0279
0.5000 1.4019 1.4550 0.0531 0.0365
plot(x1,y1,'r','linewidth',2)
hold on, grid on, grid minor
plot(x1,solex,'b','linewidth',2)
[x2,y2]=RK2('ejercicio08',0,0.5,0.1,1)
x2 = 1×6
0 0.1000 0.2000 0.3000 0.4000 0.5000
y2 = 6×1
1.0000
1.0565
1.1274
1.2151
1.3228
1.4544
plot(x2,y2,'y','linewidth',2)
legend('Euler','Sol Exacta','RK2','Location','northwest')
17
erel=eabs./solex;
resp2=[x3,y3,solex,eabs,erel]
resp2 = 11×5
0 1.0000 1.0000 0 0
0.0500 1.0250 1.0266 0.0016 0.0016
0.1000 1.0532 1.0565 0.0034 0.0032
0.1500 1.0848 1.0901 0.0053 0.0049
0.2000 1.1200 1.1275 0.0075 0.0066
0.2500 1.1592 1.1691 0.0099 0.0084
0.3000 1.2027 1.2153 0.0126 0.0104
0.3500 1.2508 1.2665 0.0157 0.0124
0.4000 1.3040 1.3231 0.0192 0.0145
0.4500 1.3627 1.3858 0.0231 0.0167
plot(x3,y3,'r','linewidth',2)
hold on, grid on, grid minor
plot(x3,solex,'k','linewidth',2)
[x4,y4]=RK2('ejercicio08',0,0.5,0.05,1)
x4 = 1×11
0 0.0500 0.1000 0.1500 0.2000 0.2500 0.3000 0.3500
y4 = 11×1
1.0000
1.0266
1.0565
1.0901
1.1275
1.1691
1.2153
1.2664
1.3230
1.3856
plot(x4,y4,'y','linewidth',2)
legend('Euler','Sol Exacta','RK2','Location','northwest')
18
Ejercicio 9: y' = xy^2-y/x, y(1) = 1; y(1.5)
resp1 = 6×5
1.0000 1.0000 1.0000 0 0
1.1000 1.0000 1.0101 0.0101 0.0100
1.2000 1.0191 1.0417 0.0226 0.0217
1.3000 1.0588 1.0989 0.0401 0.0365
1.4000 1.1231 1.1905 0.0674 0.0566
1.5000 1.2194 1.3333 0.1139 0.0854
plot(x1,y1,'r','linewidth',2)
hold on, grid on, grid minor
plot(x1,solex,'b','linewidth',2)
[x2,y2]=RK2('ejercicio09',1,1.5,0.1,1)
x2 = 1×6
1.0000 1.1000 1.2000 1.3000 1.4000 1.5000
y2 = 6×1
1.0000
1.0095
1.0404
1.0967
19
1.1866
1.3260
plot(x2,y2,'y','linewidth',2)
legend('Euler','Sol Exacta','RK2','Location','northwest')
resp2 = 11×5
1.0000 1.0000 1.0000 0 0
1.0500 1.0000 1.0025 0.0025 0.0025
1.1000 1.0049 1.0101 0.0052 0.0052
1.1500 1.0147 1.0230 0.0083 0.0081
1.2000 1.0298 1.0417 0.0118 0.0114
1.2500 1.0506 1.0667 0.0161 0.0151
1.3000 1.0775 1.0989 0.0214 0.0195
1.3500 1.1115 1.1396 0.0281 0.0246
1.4000 1.1538 1.1905 0.0367 0.0308
1.4500 1.2057 1.2539 0.0482 0.0384
plot(x3,y3,'r','linewidth',2)
hold on, grid on, grid minor
plot(x3,solex,'b','linewidth',2)
20
[x4,y4]=RK2('ejercicio09',1,1.5,0.05,1)
x4 = 1×11
1.0000 1.0500 1.1000 1.1500 1.2000 1.2500 1.3000 1.3500
y4 = 11×1
1.0000
1.0024
1.0100
1.0228
1.0414
1.0663
1.0984
1.1389
1.1895
1.2526
plot(x4,y4,'y','linewidth',2)
legend('Euler','Sol Exacta','RK2','Location','northwest')
21
resp1 = 6×5
0 0.5000 0.5000 0 0
0.1000 0.5250 0.5250 -0.0000 -0.0000
0.2000 0.5499 0.5498 -0.0001 -0.0002
0.3000 0.5747 0.5744 -0.0002 -0.0004
0.4000 0.5991 0.5987 -0.0004 -0.0007
0.5000 0.6231 0.6225 -0.0007 -0.0011
plot(x1,y1,'r','linewidth',2)
hold on, grid on, grid minor
plot(x1,solex,'b','linewidth',2)
[x2,y2]=RK2('ejercicio10',0,0.5,0.1,0.5)
x2 = 1×6
0 0.1000 0.2000 0.3000 0.4000 0.5000
y2 = 6×1
0.5000
0.5250
0.5498
0.5744
0.5986
0.6224
plot(x2,y2,'y','linewidth',2)
legend('Euler','Sol Exacta','RK2','Location','northwest')
22
erel=eabs./solex;
resp2=[x3,y3,solex,eabs,erel]
resp2 = 11×5
0 0.5000 0.5000 0 0
0.0500 0.5125 0.5125 -0.0000 -0.0000
0.1000 0.5250 0.5250 -0.0000 -0.0000
0.1500 0.5375 0.5374 -0.0000 -0.0001
0.2000 0.5499 0.5498 -0.0001 -0.0001
0.2500 0.5623 0.5622 -0.0001 -0.0002
0.3000 0.5746 0.5744 -0.0001 -0.0002
0.3500 0.5868 0.5866 -0.0002 -0.0003
0.4000 0.5989 0.5987 -0.0002 -0.0004
0.4500 0.6109 0.6106 -0.0003 -0.0005
plot(x3,y3,'r','linewidth',2)
hold on, grid on, grid minor
plot(x3,solex,'b','linewidth',2)
[x4,y4]=RK2('ejercicio10',0,0.5,0.05,0.5)
x4 = 1×11
0 0.0500 0.1000 0.1500 0.2000 0.2500 0.3000 0.3500
y4 = 11×1
0.5000
0.5125
0.5250
0.5374
0.5498
0.5622
0.5744
0.5866
0.5987
0.6106
plot(x4,y4,'y','linewidth',2)
legend('Euler','Sol Exacta','RK2','Location','northwest')
23
En los problemas 11 y 12 utilice un solucionador para obtener una curva solución numérica para el
problema con valores iniciales dado. Primero utilice el método de Euler y después el método RK4.
Utilice h = 0.25 en cada caso. Superponga ambas curvas solución en los mismos ejes coordenados. Si
es posible, utilice un color diferente para cada curva. Repita, usando h = 0.1 y h = 0.05.
resp1 = 5×5
0 1.0000 1.0000 0 0
0.2500 1.5000 1.6402 0.1402 0.0855
0.5000 2.2267 2.6087 0.3820 0.1464
0.7500 3.2037 3.9090 0.7053 0.1804
1.0000 4.3758 5.3814 1.0056 0.1869
plot(x1,y1,'r','linewidth',2)
hold on, grid on, grid minor
plot(x1,solex,'b','linewidth',2)
[x2,y2]=RK4('ejercicio11',0,1,0.25,1)
y = 5×1
0
24
0
0
0
0
x2 = 1×5
0 0.2500 0.5000 0.7500 1.0000
y2 = 5×1
1.0000
1.6399
2.6079
3.9075
5.3792
plot(x2,y2,'y','linewidth',2)
legend('Euler','Sol Exacta','RK4','Location','northwest')
resp2 = 11×5
0 1.0000 1.0000 0 0
0.1000 1.2000 1.2210 0.0210 0.0172
0.2000 1.4388 1.4879 0.0491 0.0330
0.3000 1.7208 1.8059 0.0850 0.0471
0.4000 2.0496 2.1789 0.1293 0.0593
0.5000 2.4272 2.6087 0.1815 0.0696
25
0.6000 2.8532 3.0934 0.2402 0.0777
0.7000 3.3242 3.6271 0.3029 0.0835
0.8000 3.8327 4.1984 0.3658 0.0871
0.9000 4.3667 4.7906 0.4239 0.0885
plot(x3,y3,'r','linewidth',2)
hold on, grid on, grid minor
plot(x3,solex,'b','linewidth',2)
[x4,y4]=RK4('ejercicio11',0,1,0.1,1)
y = 11×1
0
0
0
0
0
0
0
0
0
0
x4 = 1×11
0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000
y4 = 11×1
1.0000
1.2210
1.4879
1.8059
2.1789
2.6087
3.0934
3.6271
4.1984
4.7905
plot(x4,y4,'y','linewidth',2)
legend('Euler','Sol Exacta','RK4','Location','northwest')
26
clear, close, clc
[x5,y5] = euler('ejercicio11',0,1,0.05,1);
solex=exp(2.*sin(x5));
eabs=solex-y5;
erel=eabs./solex;
resp3=[x5,y5,solex,eabs,erel]
resp3 = 21×5
0 1.0000 1.0000 0 0
0.0500 1.1000 1.1051 0.0051 0.0046
0.1000 1.2099 1.2210 0.0111 0.0091
0.1500 1.3302 1.3483 0.0181 0.0134
0.2000 1.4618 1.4879 0.0261 0.0175
0.2500 1.6050 1.6402 0.0351 0.0214
0.3000 1.7606 1.8059 0.0453 0.0251
0.3500 1.9287 1.9854 0.0566 0.0285
0.4000 2.1099 2.1789 0.0690 0.0317
0.4500 2.3043 2.3867 0.0825 0.0346
plot(x5,y5,'r','linewidth',2)
hold on, grid on, grid minor
plot(x5,solex,'b','linewidth',2)
[x6,y6]=RK4('ejercicio11',0,1,0.05,1)
y = 21×1
0
0
0
27
0
0
0
0
0
0
0
x6 = 1×21
0 0.0500 0.1000 0.1500 0.2000 0.2500 0.3000 0.3500
y6 = 21×1
1.0000
1.1051
1.2210
1.3483
1.4879
1.6402
1.8059
1.9853
2.1789
2.3867
plot(x6,y6,'y','linewidth',2)
legend('Euler','Sol Exacta','RK4','Location','northwest')
28
[x1,y1] = euler('ejercicio12',0,1,0.25,1);
solex=5./(exp(log(4) - 10.*x1) + 1);
eabs=solex-y1;
erel=eabs./solex;
resp1=[x1,y1,solex,eabs,erel]
resp1 = 5×5
0 1.0000 1.0000 0 0
0.2500 3.0000 3.7641 0.7641 0.2030
0.5000 6.0000 4.8688 -1.1312 -0.2323
0.7500 3.0000 4.9890 1.9890 0.3987
1.0000 6.0000 4.9991 -1.0009 -0.2002
plot(x1,y1,'r','linewidth',2)
hold on, grid on, grid minor
plot(x1,solex,'b','linewidth',2)
[x2,y2]=RK4('ejercicio12',0,1,0.25,1)
y = 5×1
0
0
0
0
0
x2 = 1×5
0 0.2500 0.5000 0.7500 1.0000
y2 = 5×1
1.0000
3.6758
4.4568
4.6634
4.7797
plot(x2,y2,'y','linewidth',2)
legend('Euler','Sol Exacta','RK4','Location','northwest')
29
clear, close, clc
[x3,y3] = euler('ejercicio12',0,1,0.1,1);
solex=5./(exp(log(4) - 10.*x3) + 1);
eabs=solex-y3;
erel=eabs./solex;
resp2=[x3,y3,solex,eabs,erel]
resp2 = 11×5
0 1.0000 1.0000 0 0
0.1000 1.8000 2.0230 0.2230 0.1103
0.2000 2.9520 3.2439 0.2919 0.0900
0.3000 4.1611 4.1696 0.0085 0.0020
0.4000 4.8593 4.6587 -0.2006 -0.0431
0.5000 4.9960 4.8688 -0.1273 -0.0261
0.6000 5.0000 4.9509 -0.0491 -0.0099
0.7000 5.0000 4.9818 -0.0182 -0.0036
0.8000 5.0000 4.9933 -0.0067 -0.0013
0.9000 5.0000 4.9975 -0.0025 -0.0005
plot(x3,y3,'r','linewidth',2)
hold on, grid on, grid minor
plot(x3,solex,'b','linewidth',2)
[x4,y4]=RK4('ejercicio12',0,1,0.1,1)
y = 11×1
0
0
0
30
0
0
0
0
0
0
0
x4 = 1×11
0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000
y4 = 11×1
1.0000
2.0215
3.2418
4.1665
4.6544
4.8651
4.9487
4.9806
4.9927
4.9973
plot(x4,y4,'y','linewidth',2)
legend('Euler','Sol Exacta','RK4','Location','northwest')
31
eabs=solex-y5;
erel=eabs./solex;
resp3=[x5,y5,solex,eabs,erel]
resp3 = 21×5
0 1.0000 1.0000 0 0
0.0500 1.4000 1.4594 0.0594 0.0407
0.1000 1.9040 2.0230 0.1190 0.0588
0.1500 2.4935 2.6420 0.1485 0.0562
0.2000 3.1185 3.2439 0.1255 0.0387
0.2500 3.7052 3.7641 0.0589 0.0156
0.3000 4.1850 4.1696 -0.0153 -0.0037
0.3500 4.5261 4.4611 -0.0649 -0.0146
0.4000 4.7406 4.6587 -0.0819 -0.0176
0.4500 4.8636 4.7873 -0.0763 -0.0159
plot(x5,y5,'r','linewidth',2)
hold on, grid on, grid minor
plot(x5,solex,'b','linewidth',2)
[x6,y6]=RK4('ejercicio12',0,1,0.05,1)
y = 21×1
0
0
0
0
0
0
0
0
0
0
x6 = 1×21
0 0.0500 0.1000 0.1500 0.2000 0.2500 0.3000 0.3500
y6 = 21×1
1.0000
1.4593
2.0229
2.6418
3.2438
3.7639
4.1694
4.4609
4.6585
4.7871
plot(x6,y6,'y','linewidth',2)
legend('Euler','Sol Exacta','RK4','Location','northwest')
32
33