Y Y H F (X, Y: Ecuaciones Diferenciales Primer Orden Metodo Euler
Y Y H F (X, Y: Ecuaciones Diferenciales Primer Orden Metodo Euler
Y Y H F (X, Y: Ecuaciones Diferenciales Primer Orden Metodo Euler
PRIMER ORDEN
METODO EULER
Y i+1=Y i+ h∗f (X i , Y i)
EJEMPLO 1
dy
=x− y
dx
[0,1]
y ( 0 )=2
y (1 )=?
a ¿ h=0,1
b ¿ h=0,01
b−a
Para encontrar N se usa la formula N=
h
1−0
N= =10
0,1
1−0
N= =10 0
0, 0 1
EXCEL
MATLAB
>> yi=dsolve('Dy=x-y','y(0)=2','x')
yi =
x + 3/exp(x) - 1
>> y1=subs(yi,'x',1)
y1 =
1.103638323514327
>> error=abs(y1-1.098097)
error =
0.005541323514326
>> ezplot(yi,[0,1]);grid on
x + 3/exp(x) - 1
1.9
1.8
1.7
1.6
1.5
1.4
1.3
1.2
1.1
EDITOR
function [x,y] = Euler(f,a,b,N,y0)
h=(b-a)/N;
x=a:h:b;
x=x(:);
y=zeros(N+1,1);
y(1)=y0;
for k=1:N
y(k+1)=y(k)+h*feval(f,x(k),y(k));
end
end
function z=ejemplo1(x,y)
z=x-y;
end
??? Input argument "b" is undefined.
h=(b-a)/N;
>> [x,y]=Euler('ejemplo1',0,1,100,2)
x=
0.010000000000000
0.020000000000000
0.030000000000000
0.040000000000000
0.050000000000000
0.060000000000000
0.070000000000000
0.080000000000000
0.090000000000000
0.100000000000000
0.110000000000000
0.120000000000000
0.130000000000000
0.140000000000000
0.150000000000000
0.160000000000000
0.170000000000000
0.180000000000000
0.190000000000000
0.200000000000000
0.210000000000000
0.220000000000000
0.230000000000000
0.240000000000000
0.250000000000000
0.260000000000000
0.270000000000000
0.280000000000000
0.290000000000000
0.300000000000000
0.310000000000000
0.320000000000000
0.330000000000000
0.340000000000000
0.350000000000000
0.360000000000000
0.370000000000000
0.380000000000000
0.390000000000000
0.400000000000000
0.410000000000000
0.420000000000000
0.430000000000000
0.440000000000000
0.450000000000000
0.460000000000000
0.470000000000000
0.480000000000000
0.490000000000000
0.500000000000000
0.510000000000000
0.520000000000000
0.530000000000000
0.540000000000000
0.550000000000000
0.560000000000000
0.570000000000000
0.580000000000000
0.590000000000000
0.600000000000000
0.610000000000000
0.620000000000000
0.630000000000000
0.640000000000000
0.650000000000000
0.660000000000000
0.670000000000000
0.680000000000000
0.690000000000000
0.700000000000000
0.710000000000000
0.720000000000000
0.730000000000000
0.740000000000000
0.750000000000000
0.760000000000000
0.770000000000000
0.780000000000000
0.790000000000000
0.800000000000000
0.810000000000000
0.820000000000000
0.830000000000000
0.840000000000000
0.850000000000000
0.860000000000000
0.870000000000000
0.880000000000000
0.890000000000000
0.900000000000000
0.910000000000000
0.920000000000000
0.930000000000000
0.940000000000000
0.950000000000000
0.960000000000000
0.970000000000000
0.980000000000000
0.990000000000000
1.000000000000000
y=
2.000000000000000
1.980000000000000
1.960300000000000
1.940897000000000
1.921788030000000
1.902970149700000
1.884440448203000
1.866196043720970
1.848234083283760
1.830551742450922
1.813146225026413
1.796014762776149
1.779154615148388
1.762563068996904
1.746237438306935
1.730175063923865
1.714373313284627
1.698829580151780
1.683541284350262
1.668505871506760
1.653720812791692
1.639183604663775
1.624891768617138
1.610842850930966
1.597034422421657
1.583464078197440
1.570129437415466
1.557028143041311
1.544157861610898
1.531516282994789
1.519101120164841
1.506910108963193
1.494941007873561
1.483191597794825
1.471659681816877
1.460343084998708
1.449239654148721
1.438347257607234
1.427663785031162
1.417187147180850
1.406915275709042
1.396846122951951
1.386977661722432
1.377307885105208
1.367834806254156
1.358556458191614
1.349470893609698
1.340576184673601
1.331870422826865
1.323351718598596
1.315018201412610
1.306868019398484
1.298899339204499
1.291110345812454
1.283499242354330
1.276064249930787
1.268803607431479
1.261715571357164
1.254798415643592
1.248050431487156
1.241469927172285
1.235055227900562
1.228804675621556
1.222716628865340
1.216789462576687
1.211021567950920
1.205411352271411
1.199957238748697
1.194657666361210
1.189511089697598
1.184515978800622
1.179670819012616
1.174974110822490
1.170424369714265
1.166020126017122
1.161759924756951
1.157642325509382
1.153665902254288
1.149829243231745
1.146130950799427
1.142569641291433
1.139143944878519
1.135852505429734
1.132693980375436
1.129667040571682
1.126770370165965
1.124002666464306
1.121362639799662
1.118849013401666
1.116460523267649
1.114195918034973
1.112053958854623
1.110033419266077
1.108133085073416
1.106351754222682
1.104688236680455
1.103141354313650
1.101709940770514
1.100392841362809
1.099188912949181
1.098097023819689
EJEMPLO 2
>> [x,y]=Euler('ejemplo1',0,3,300,1)
x=
0.010000000000000
0.020000000000000
0.030000000000000
0.040000000000000
0.050000000000000
0.060000000000000
0.070000000000000
0.080000000000000
0.090000000000000
0.100000000000000
0.110000000000000
0.120000000000000
0.130000000000000
0.140000000000000
0.150000000000000
0.160000000000000
0.170000000000000
0.180000000000000
0.190000000000000
0.200000000000000
0.210000000000000
0.220000000000000
0.230000000000000
0.240000000000000
0.250000000000000
0.260000000000000
0.270000000000000
0.280000000000000
0.290000000000000
0.300000000000000
0.310000000000000
0.320000000000000
0.330000000000000
0.340000000000000
0.350000000000000
0.360000000000000
0.370000000000000
0.380000000000000
0.390000000000000
0.400000000000000
0.410000000000000
0.420000000000000
0.430000000000000
0.440000000000000
0.450000000000000
0.460000000000000
0.470000000000000
0.480000000000000
0.490000000000000
0.500000000000000
0.510000000000000
0.520000000000000
0.530000000000000
0.540000000000000
0.550000000000000
0.560000000000000
0.570000000000000
0.580000000000000
0.590000000000000
0.600000000000000
0.610000000000000
0.620000000000000
0.630000000000000
0.640000000000000
0.650000000000000
0.660000000000000
0.670000000000000
0.680000000000000
0.690000000000000
0.700000000000000
0.710000000000000
0.720000000000000
0.730000000000000
0.740000000000000
0.750000000000000
0.760000000000000
0.770000000000000
0.780000000000000
0.790000000000000
0.800000000000000
0.810000000000000
0.820000000000000
0.830000000000000
0.840000000000000
0.850000000000000
0.860000000000000
0.870000000000000
0.880000000000000
0.890000000000000
0.900000000000000
0.910000000000000
0.920000000000000
0.930000000000000
0.940000000000000
0.950000000000000
0.960000000000000
0.970000000000000
0.980000000000000
0.990000000000000
1.000000000000000
1.010000000000000
1.020000000000000
1.030000000000000
1.040000000000000
1.050000000000000
1.060000000000000
1.070000000000000
1.080000000000000
1.090000000000000
1.100000000000000
1.110000000000000
1.120000000000000
1.130000000000000
1.140000000000000
1.150000000000000
1.160000000000000
1.170000000000000
1.180000000000000
1.190000000000000
1.200000000000000
1.210000000000000
1.220000000000000
1.230000000000000
1.240000000000000
1.250000000000000
1.260000000000000
1.270000000000000
1.280000000000000
1.290000000000000
1.300000000000000
1.310000000000000
1.320000000000000
1.330000000000000
1.340000000000000
1.350000000000000
1.360000000000000
1.370000000000000
1.380000000000000
1.390000000000000
1.400000000000000
1.410000000000000
1.420000000000000
1.430000000000000
1.440000000000000
1.450000000000000
1.460000000000000
1.470000000000000
1.480000000000000
1.490000000000000
1.500000000000000
1.510000000000000
1.520000000000000
1.530000000000000
1.540000000000000
1.550000000000000
1.560000000000000
1.570000000000000
1.580000000000000
1.590000000000000
1.600000000000000
1.610000000000000
1.620000000000000
1.630000000000000
1.640000000000000
1.650000000000000
1.660000000000000
1.670000000000000
1.680000000000000
1.690000000000000
1.700000000000000
1.710000000000000
1.720000000000000
1.730000000000000
1.740000000000000
1.750000000000000
1.760000000000000
1.770000000000000
1.780000000000000
1.790000000000000
1.800000000000000
1.810000000000000
1.820000000000000
1.830000000000000
1.840000000000000
1.850000000000000
1.860000000000000
1.870000000000000
1.880000000000000
1.890000000000000
1.900000000000000
1.910000000000000
1.920000000000000
1.930000000000000
1.940000000000000
1.950000000000000
1.960000000000000
1.970000000000000
1.980000000000000
1.990000000000000
2.000000000000000
2.010000000000000
2.020000000000000
2.030000000000000
2.040000000000000
2.050000000000000
2.060000000000000
2.070000000000000
2.080000000000000
2.090000000000000
2.100000000000000
2.110000000000000
2.120000000000000
2.130000000000000
2.140000000000000
2.150000000000000
2.160000000000000
2.170000000000000
2.180000000000000
2.190000000000000
2.200000000000000
2.210000000000000
2.220000000000000
2.230000000000000
2.240000000000000
2.250000000000000
2.260000000000000
2.270000000000000
2.280000000000000
2.290000000000000
2.300000000000000
2.310000000000000
2.320000000000000
2.330000000000000
2.340000000000000
2.350000000000000
2.360000000000000
2.370000000000000
2.380000000000000
2.390000000000000
2.400000000000000
2.410000000000000
2.420000000000000
2.430000000000000
2.440000000000000
2.450000000000000
2.460000000000000
2.470000000000000
2.480000000000000
2.490000000000000
2.500000000000000
2.510000000000000
2.520000000000000
2.530000000000000
2.540000000000000
2.550000000000000
2.560000000000000
2.570000000000000
2.580000000000000
2.590000000000000
2.600000000000000
2.610000000000000
2.620000000000000
2.630000000000000
2.640000000000000
2.650000000000000
2.660000000000000
2.670000000000000
2.680000000000000
2.690000000000000
2.700000000000000
2.710000000000000
2.720000000000000
2.730000000000000
2.740000000000000
2.750000000000000
2.760000000000000
2.770000000000000
2.780000000000000
2.790000000000000
2.800000000000000
2.810000000000000
2.820000000000000
2.830000000000000
2.840000000000000
2.850000000000000
2.860000000000000
2.870000000000000
2.880000000000000
2.890000000000000
2.900000000000000
2.910000000000000
2.920000000000000
2.930000000000000
2.940000000000000
2.950000000000000
2.960000000000000
2.970000000000000
2.980000000000000
2.990000000000000
3.000000000000000
y=
1.000000000000000
1.010000000000000
1.019898000000000
1.029689020800000
1.039368097595520
1.048930284093399
1.058370656650239
1.067684318428761
1.076866403567249
1.085912081357214
1.094816560424343
1.103575092907738
1.112182978632418
1.120635569270024
1.128928272482622
1.137056556044497
1.145015951936808
1.152802060409979
1.160410554008685
1.167837181554340
1.175077772079977
1.182128238712457
1.188984582496989
1.195642896158972
1.202099367798231
1.208350284510782
1.214392035933336
1.220221117705816
1.225834134847262
1.231227805040590
1.236398961821761
1.241344557669048
1.246061666988190
1.250547488989348
1.254799350451912
1.258814708373358
1.262591152498478
1.266126407725474
1.269418336385560
1.272464940392885
1.275264363261750
1.277814891988273
1.280114958793852
1.282163142727922
1.283958171127741
1.285498920933095
1.286784419854028
1.287813847389911
1.288586535698345
1.289101970312624
1.289359790706687
1.289359790706687
1.289101918748545
1.288586277981046
1.287813126214257
1.286782875713286
1.285496092837573
1.283953497526168
1.282155962629631
1.280104513089424
1.277800324965863
1.275244724315931
1.272439185922436
1.269385331876222
1.266084930013344
1.262539892209307
1.258752272532679
1.254724265260574
1.250458202758688
1.245956553228757
1.241221918326487
1.236257030653182
1.231064751124438
1.225648066219491
1.220010085114881
1.214154036706330
1.208083266522798
1.201801233536879
1.195311506875780
1.188617762437276
1.181723779415140
1.174633436738649
1.167350709430869
1.159879664890512
1.152224459102234
1.144389332780339
1.136378607450877
1.128196681477230
1.119848026034299
1.111337181036438
1.102668751024354
1.093847401016159
1.084877852327827
1.075764878368273
1.066513300414306
1.057127983370660
1.047613831520324
1.037975784270337
1.028218811898196
1.018347911303973
1.008368101773194
0.998284420755462
0.988101919663756
0.977825659699253
0.967460707706441
0.957012132063212
0.946484998610516
0.935884366626079
0.925215284846541
0.914482787542321
0.903691890649322
0.892847587961530
0.881954847388399
0.871018607280783
0.860043772829045
0.849035212536834
0.837997754773855
0.826936184410840
0.815855239539735
0.804759608281994
0.793653925687703
0.782542770728075
0.771430663383736
0.760322061831010
0.749221359728278
0.738132883604299
0.727060890350235
0.716009564816911
0.704983017518731
0.693985282445438
0.683020314982800
0.672091989943076
0.661204099705998
0.650360352470819
0.639564370619804
0.628819689193391
0.618129754477104
0.607497922700097
0.596927458845116
0.586421535569442
0.575983232236305
0.565615534056052
0.555321331336232
0.545103418839645
0.534964495249228
0.524907162738542
0.514933926646510
0.505047195254897
0.495249279666952
0.485542393785480
0.475928654388527
0.466410081300757
0.456988597658481
0.447666030266248
0.438444110042764
0.429324472553874
0.420308658630243
0.411398115067282
0.402594195404842
0.393898160784097
0.385311180879004
0.376834334899666
0.368468612664893
0.360214915741200
0.352074058645448
0.344046770108332
0.336133694395841
0.328335392685857
0.320652344497008
0.313084949166879
0.305633527376707
0.298298322719666
0.291079503309850
0.283977163429090
0.276991325208734
0.270121940343557
0.263368891834969
0.256731995760727
0.250211003068405
0.243805601389854
0.237515416873995
0.231340016035272
0.225278907615147
0.219331544454108
0.213497325371628
0.207775597051669
0.202165655931274
0.196666750089943
0.191278081137479
0.185998806098084
0.180828039288557
0.175764854188478
0.170808285300363
0.165957329997832
0.161210950359894
0.156568074989529
0.152027600814833
0.147588394871040
0.143249296061831
0.139009116898401
0.134866645214829
0.130820645858384
0.126869862353461
0.123013018537916
0.119248820170655
0.115575956509399
0.111993101857608
0.108498917079650
0.105092051083349
0.101771142269116
0.098534819944958
0.095381705706719
0.092310414782963
0.089319557343995
0.086407739774580
0.083573565909974
0.080815638234945
0.078132559045545
0.075522931573424
0.072985361072557
0.070518455868304
0.068120828368782
0.065791096038570
0.063527882334843
0.061329817606057
0.059195539953366
0.057123696054999
0.055112941953863
0.053161943808696
0.051269378609106
0.049433934854900
0.047654313200124
0.045929227062279
0.044257403197212
0.042637582240194
0.041068519213755
0.039548984002846
0.038077761797940
0.036653653506698
0.035275476134846
0.033942063136949
0.032652264737744
0.031404948224763
0.030198998212932
0.029033316881913
0.027906824186894
0.026818458043605
0.025767174488296
0.024751947813457
0.023771770680044
0.022825654206979
0.021912628038699
0.021031740391544
0.020182058079725
0.019362666521689
0.018572669727604
0.017811190268772
0.017077369229698
0.016370366143589
0.015689358912016
0.015033543709493
0.014402134873695
0.013794364782025
0.013209483715267
0.012646759708997
0.012105478393452
0.011584942822533
0.011084473292600
0.010603407151701
0.010141098599887
0.009696918481212
0.009270254068038
0.008860508838231
0.008467102245814
0.008089469485650
0.007727061252693
0.007379343496322
0.007045797170288
0.006725917978757
0.006419216118926
0.006125216020679
0.005843456083728
0.005573488412660
0.005314878550312
0.005067205209868
0.004830060006046
0.004603047185762
0.004385783358594
0.004177897227396
0.003979029319372
0.003788831717906
0.003606967795447
0.003433111947706
0.003266949329437
0.003108175592027
0.002956496623136
0.002811628288602
0.002673296176803
0.002541235345669
0.002415190072524
0.002294913606912
>> y2=y(end)
y2 =
0.002294913606912
>> yi=dsolve('Dy=(1-2*x)*y','y(0)=1','x')
yi =
exp(1/4)/exp((2*x - 1)^2/4)
>> y1=subs(yi,'x',3)
y1 =
0.002478752176666
>> error=abs(y1-y2)
error =
1.838385697544207e-004