Buscar

Oscilador Harmônico Simples e Runge-Kutta de 4ª Ordem

Faça como milhares de estudantes: teste grátis o Passei Direto

Esse e outros conteúdos desbloqueados

16 milhões de materiais de várias disciplinas

Impressão de materiais

Agora você pode testar o

Passei Direto grátis

Você também pode ser Premium ajudando estudantes

Faça como milhares de estudantes: teste grátis o Passei Direto

Esse e outros conteúdos desbloqueados

16 milhões de materiais de várias disciplinas

Impressão de materiais

Agora você pode testar o

Passei Direto grátis

Você também pode ser Premium ajudando estudantes

Faça como milhares de estudantes: teste grátis o Passei Direto

Esse e outros conteúdos desbloqueados

16 milhões de materiais de várias disciplinas

Impressão de materiais

Agora você pode testar o

Passei Direto grátis

Você também pode ser Premium ajudando estudantes
Você viu 3, do total de 11 páginas

Faça como milhares de estudantes: teste grátis o Passei Direto

Esse e outros conteúdos desbloqueados

16 milhões de materiais de várias disciplinas

Impressão de materiais

Agora você pode testar o

Passei Direto grátis

Você também pode ser Premium ajudando estudantes

Faça como milhares de estudantes: teste grátis o Passei Direto

Esse e outros conteúdos desbloqueados

16 milhões de materiais de várias disciplinas

Impressão de materiais

Agora você pode testar o

Passei Direto grátis

Você também pode ser Premium ajudando estudantes

Faça como milhares de estudantes: teste grátis o Passei Direto

Esse e outros conteúdos desbloqueados

16 milhões de materiais de várias disciplinas

Impressão de materiais

Agora você pode testar o

Passei Direto grátis

Você também pode ser Premium ajudando estudantes
Você viu 6, do total de 11 páginas

Faça como milhares de estudantes: teste grátis o Passei Direto

Esse e outros conteúdos desbloqueados

16 milhões de materiais de várias disciplinas

Impressão de materiais

Agora você pode testar o

Passei Direto grátis

Você também pode ser Premium ajudando estudantes

Faça como milhares de estudantes: teste grátis o Passei Direto

Esse e outros conteúdos desbloqueados

16 milhões de materiais de várias disciplinas

Impressão de materiais

Agora você pode testar o

Passei Direto grátis

Você também pode ser Premium ajudando estudantes

Faça como milhares de estudantes: teste grátis o Passei Direto

Esse e outros conteúdos desbloqueados

16 milhões de materiais de várias disciplinas

Impressão de materiais

Agora você pode testar o

Passei Direto grátis

Você também pode ser Premium ajudando estudantes
Você viu 9, do total de 11 páginas

Faça como milhares de estudantes: teste grátis o Passei Direto

Esse e outros conteúdos desbloqueados

16 milhões de materiais de várias disciplinas

Impressão de materiais

Agora você pode testar o

Passei Direto grátis

Você também pode ser Premium ajudando estudantes

Prévia do material em texto

*********************************** Primeiro arquivo .java ***********************************
/*
* Autor: Rafael Alves Viana
* Tema: Oscilador Hamônicos simples e Runge-Kutta de 4ordem
* Arquivo .java: 1
* */
package OsciladorHamonicoSimples_RungeKutta4;
public class OHS1
{
public static void main(String[] args)
 {
//Objeto solução do tipo OHS2
OHS2 solucao = new OHS2();
//Chamada de métoddo - rungeKutta de quarta ordem
solucao.rungeKutta4(0, 10,0, 0.02, 100);
 }// fim o método principal main
}// fim da classe OHS1
*********************************** Segundo arquivo .java ***********************************
/*
 * Autor: Rafael Alves Viana
 * Tema: Oscilador Hamônicos simples e Runge-Kutta de 4ordem
 * Arquivo .java: 2
 * */
package OsciladorHamonicoSimples_RungeKutta4;
public class OHS2
{
/*
 Expressões para as derivadas - du1(t, b1, b2, .... bn)/dt = f1(t, b1, b2, .... bn)
 du2(t, b1, b2, .... bn)/dt = f2(t, b1, b2, .... bn)
 .
 .
 .
 dun(t, b1, b2, .... bn)/dt = fn(t, b1, b2, .... bn)
 */
 //Primeira edo
public double f1(double t, double x, double z)
 {
return (z);
 }
//Segunda edo
public double f2(double t, double x, double z)
 {
//w = 2*pi*f rds/s e f = 2Hz
double f = 2;
double pi = Math.PI;
double w = 2*pi*f;
return (-Math.pow(w,2)*x);
 }
//Rotina para o método de Runge-Kutta de 4 Ordem
public void rungeKutta4(double t0, double x0, double z0, double h, int N)
 {
// Declarano arrsys
double []t = new double[N+1]; // tempo
double []x = new double[N+1]; // Posição da massa no instante de tempo t
double []z = new double[N+1]; // velocidade da massa no instatante de tempo t
 //Inciando
t[0] = t0; // tempo inicial
x[0] = x0; // posição inicial
z[0] = z0; // velociade inicial
 //Loop
for(int i = 0; i < N; i++)
 {
double k11 = h*f1(t[i],x[i],z[i]);
double k12 = h*f2(t[i],x[i],z[i]);
double k21 = h*f1((t[i] + (h/2)), (x[i] + (k11/2)), (z[i] + (k12/2)));
double k22 = h*f2((t[i] + (h/2)), (x[i] + (k11/2)), (z[i] + (k12/2)));
double k31 = h*f1((t[i] + (h/2)), (x[i] + (k21/2)), (z[i] + (k22/2)));
double k32 = h*f2((t[i] + (h/2)), (x[i] + (k21/2)), (z[i] + (k22/2)));
double k41 = h*f1((t[i] + h),(x[i] + k31),(z[i] + k32));
double k42 = h*f2((t[i] + h),(x[i] + k31),(z[i] + k32));
x[i+1] = x[i] + ((k11 + 2*k21 + 2*k31 + k41)/6);
z[i+1] = z[i] + ((k12 + 2*k22 + 2*k32 + k42)/6);
t[i+1] = t[i] + h;
//Saída + erro
System.out.println("t = "+t[i]+" || x = "+x[i]+" || z = "+z[i]);
 }// fim do loop
}// fim do método rungeKutta4
}// fim da classe OHS2
*********************************** Saída dos dados***********************************
t = 0.0 || x = 10.0 || z = 0.0
t = 0.02 || x = 9.685835107652121 || z = -31.250244386089886
t = 0.04 || x = 8.763115073264105 || z = -60.5369428394996
t = 0.06 || x = 7.2898160538978845 || z = -86.02003338876861
t = 0.08 || x = 5.358506610810779 || z = -106.09843925722929
t = 0.1 || x = 3.0905315523713432 || z = -119.51066289570825
t = 0.12000000000000001 || x = 0.6283877997881735 || z = -125.41404407085548
t = 0.14 || x = -1.8732286974814243 || z = -123.43770233667401
t = 0.16 || x = -4.257142474147679 || z = -113.7058376313138
t = 0.18 || x = -6.373573814506271 || z = -96.82992513708525
t = 0.19999999999999998 || x = -8.089549312271224 || z = -73.87029490480029
t = 0.21999999999999997 || x = -9.297256465612994 || z = -46.26951028197291
t = 0.23999999999999996 || x = -9.920817395991401 || z = -15.761731043244364
t = 0.25999999999999995 || x = -9.9210561068666 || z = 15.736244023847654
t = 0.27999999999999997 || x = -9.297959764747064 || z = 46.24540927364552
t = 0.3 || x = -8.09067936951063 || z = 73.84889236507934
t = 0.32 || x = -6.375069780427533 || z = 96.8123901877611
t = 0.34 || x = -4.258923665379733 || z = 113.69313363530689
t = 0.36000000000000004 || x = -1.8751988298998898 || z = 123.4305350628658
t = 0.38000000000000006 || x = 0.6263355434322437 || z = 125.4128231575073
t = 0.4000000000000001 || x = 3.0885088770951667 || z = 119.51547866887991
t = 0.4200000000000001 || x = 5.35662417403956 || z = 106.10905620010531
t = 0.4400000000000001 || x = 7.28817754497103 || z = 86.03590072596388
t = 0.46000000000000013 || x = 8.76181161494576 || z = 60.55722183604563
t = 0.48000000000000015 || x = 9.684940273827939 || z = 31.27385110495125
t = 0.5000000000000001 || x = 9.999565715919923 || z = 0.025661456201447663
t = 0.5200000000000001 || x = 9.68592229331755 || z = -31.224031974387398
t = 0.5400000000000001 || x = 8.763718249031873 || z = -60.511826387082344
t = 0.5600000000000002 || x = 7.29089732074073 || z = -85.9975909461234
t = 0.5800000000000002 || x = 5.359998031607079 || z = -106.08008086265039
t = 0.6000000000000002 || x = 3.0923394204652013 || z = -119.4975419838717
t = 0.6200000000000002 || x = 0.6303985266217906 || z = -125.40698500397949
t = 0.6400000000000002 || x = -1.871141445585756 || z = -123.43714861139095
t = 0.6600000000000003 || x = -4.255109838460783 || z = -113.71182401531864
t = 0.6800000000000003 || x = -6.3717235043341525 || z = -96.84207548611779
t = 0.7000000000000003 || x = -8.08799758105441 || z = -73.88784579703012
t = 0.7200000000000003 || x = -9.296100806820098 || z = -46.29135898476065
t = 0.7400000000000003 || x = -9.920130417717818 || z = -15.78650479846667
t = 0.7600000000000003 || x = -9.920880969990176 || z = 15.710101749145856
t = 0.7800000000000004 || x = -9.298307471253736 || z = 46.21954099041654
t = 0.8000000000000004 || x = -8.091528071356755 || z = 73.82492336382275
t = 0.8200000000000004 || x = -6.376366152355759 || z = 96.79182642238469
t = 0.8400000000000004 || x = -4.260586255427869 || z = 113.6772671052013
t = 0.8600000000000004 || x = -1.8771231770851151 || z = 123.42036263796427
t = 0.8800000000000004 || x = 0.6242703458015542 || z = 125.40898394646538
t = 0.9000000000000005 || x = 3.086432584854647 || z = 119.51821386543682
t = 0.9200000000000005 || x = 5.354667239643097 || z = 106.11819393038236
t = 0.9400000000000005 || x = 7.286462921225139 || z = 86.05086684864976
t = 0.9600000000000005 || x = 8.760447029971555 || z = 60.57707601680819
t = 0.9800000000000005 || x = 9.684011462609394 || z = 31.29734589845057
t = 1.0000000000000004 || x = 9.999131033693578 || z = 0.05132068353053043
t = 1.0200000000000005 || x = 9.686009049236914 || z = -31.197820477317112
t = 1.0400000000000005 || x = 8.764320990454625 || z = -60.486709477595795
t = 1.0600000000000005 || x = 7.291978175929305 || z = -85.9751467034296
t = 1.0800000000000005 || x = 5.361489089303809 || z = -106.06171943814446
t = 1.1000000000000005 || x = 3.0941469968273894 || z = -119.48441700260275
t = 1.1200000000000006 || x = 0.6324090514207459 || z = -125.39992108384978
t = 1.1400000000000006 || x = -1.8690542933343162 || z = -123.43658955396312
t = 1.1600000000000006 || x = -4.253077193767439 || z = -113.71780492330531
t = 1.1800000000000006 || x = -6.3698730770711585 || z = -96.8542205593148
t = 1.2000000000000006 || x = -8.086445632019428 || z = -73.9053919450845
t = 1.2200000000000006 || x = -9.2949448431675 || z = -46.31320377310536
t = 1.2400000000000007 || x = -9.919443066697486 || z = -15.811275714918025
t = 1.2600000000000007 || x = -9.920705415899688 || z = 15.683961059188093
t = 1.2800000000000007 || x = -9.298654742292532 || z = 46.19367293834034
t = 1.3000000000000007 || x = -8.09237634684149 || z = 73.80095322560919
t = 1.3200000000000007 || x = -6.3776621338171235 || z = 96.77126022338074
t = 1.3400000000000007 || x = -4.262248515436388 || z = 113.6613969977057
t = 1.3600000000000008 || x = -1.8790472753939835 || z = 123.4101857166799
t = 1.3800000000000008 || x = 0.6222053002474639 || z = 125.40513960255649
t = 1.4000000000000008 || x = 3.084356338336408 || z = 119.52094361514033
t = 1.4200000000000008 || x = 5.3527102417422565 || z = 106.12732624204376
t = 1.4400000000000008|| x = 7.2847481287385385 || z = 86.0658279214066
t = 1.4600000000000009 || x = 8.759082181622569 || z = 60.59692583361158
t = 1.4800000000000009 || x = 9.683082309930034 || z = 31.32083728814362
t = 1.5000000000000009 || x = 9.998695953374467 || z = 0.07697768106238101
t = 1.520000000000001 || x = 9.686095375443733 || z = -31.171609895942044
t = 1.540000000000001 || x = 8.764923297543787 || z = -60.461592112174344
t = 1.560000000000001 || x = 7.293058619452227 || z = -85.9527006618217
t = 1.580000000000001 || x = 5.362979783867493 || z = -106.04335498477477
t = 1.600000000000001 || x = 3.0959542814044383 || z = -119.47128795282666
t = 1.620000000000001 || x = 0.6344193741149384 || z = -125.39285231119543
t = 1.640000000000001 || x = -1.8669672408094309 || z = -123.4360251648776
t = 1.660000000000001 || x = -4.251044540157027 || z = -113.72378035548836
t = 1.680000000000001 || x = -6.368022532808107 || z = -96.86636035660476
t = 1.700000000000001 || x = -8.084893465252831 || z = -73.92293334861036
t = 1.720000000000001 || x = -9.293788574732046 || z = -46.33504464639458
t = 1.740000000000001 || x = -9.918755342992716 || z = -15.836043791765064
t = 1.7600000000000011 || x = -9.920529444638992 || z = 15.65782195497627
t = 1.7800000000000011 || x = -9.299001577886107 || z = 46.16780511852444
t = 1.8000000000000012 || x = -8.093224195964861 || z = 73.77698195158216
t = 1.8200000000000012 || x = -6.378957724789023 || z = 96.7506915918569
t = 1.8400000000000012 || x = -4.263910445361477 || z = 113.64552331382234
t = 1.8600000000000012 || x = -1.880971124764225 || z = 123.40000429984656
t = 1.8800000000000012 || x = 0.620140406846788 || z = 125.40129012639369
t = 1.9000000000000012 || x = 3.0822801376269826 || z = 119.52366791834419
t = 1.9200000000000013 || x = 5.350753180427855 || z = 106.13645313516176
t = 1.9400000000000013 || x = 7.283033167600624 || z = 86.08078394402055
t = 1.9600000000000013 || x = 8.75771706998116 || z = 60.61677128596935
t = 1.9800000000000013 || x = 9.682152815860004 || z = 31.344325273301862
t = 2.0000000000000013 || x = 9.998260475016117 || z = 0.10263244787213921
t = 2.0200000000000014 || x = 9.686181271971547 || z = -31.145400231325254
t = 2.0400000000000014 || x = 8.765525170310807 || z = -60.436474291952436
t = 2.0600000000000014 || x = 7.294138651298135 || z = -85.93025282243427
t = 2.0800000000000014 || x = 5.364470115264676 || z = -106.02498750360473
t = 2.1000000000000014 || x = 3.097761274142902 || z = -119.4581548354689
t = 2.1200000000000014 || x = 0.636429494634287 || z = -125.38577868674585
t = 2.1400000000000015 || x = -1.8648802880934143 || z = -123.43545544462191
t = 2.1600000000000015 || x = -4.249011877718921 || z = -113.72975031208271
t = 2.1800000000000015 || x = -6.366171871635815 || z = -96.87849487791655
t = 2.2000000000000015 || x = -8.083341080841173 || z = -73.94047000725499
t = 2.2200000000000015 || x = -9.292632001590594 || z = -46.35688160401625
t = 2.2400000000000015 || x = -9.91806724666584 || z = -15.860809028174774
t = 2.2600000000000016 || x = -9.920353056251983 || z = 15.631684437512021
t = 2.2800000000000016 || x = -9.299347978057153 || z = 46.14193753207614
t = 2.3000000000000016 || x = -8.094071618726932 || z = 73.7530095428851
t = 2.3200000000000016 || x = -6.380252925248891 || z = 96.73012052892092
t = 2.3400000000000016 || x = -4.265572045159356 || z = 113.62964605455362
t = 2.3600000000000017 || x = -1.8828947251335992 || z = 123.38981838829828
t = 2.3800000000000017 || x = 0.6180756656763169 || z = 125.39743551859033
t = 2.4000000000000017 || x = 3.080203982812888 || z = 119.52638677540251
t = 2.4200000000000017 || x = 5.348796055790697 || z = 106.14557460980896
t = 2.4400000000000017 || x = 7.281318037900782 || z = 86.09573491627823
t = 2.4600000000000017 || x = 8.756351695129682 || z = 60.63661237339544
t = 2.4800000000000018 || x = 9.68122298046945 || z = 31.367809853197148
t = 2.5000000000000018 || x = 9.99782459867206 || z = 0.12828498303532143
t = 2.520000000000002 || x = 9.686266738853915 || z = -31.119191484529484
t = 2.540000000000002 || x = 8.766126608767163 || z = -60.41135601806433
t = 2.560000000000002 || x = 7.295218271455696 || z = -85.9078031864018
t = 2.580000000000002 || x = 5.365960083461928 || z = -106.0066169956978
t = 2.600000000000002 || x = 3.099567974989356 || z = -119.44501765145502
t = 2.620000000000002 || x = 0.6384394129087303 || z = -125.37870021123054
t = 2.640000000000002 || x = -1.862793435268563 || z = -123.43488039368367
t = 2.660000000000002 || x = -4.246979206542484 || z = -113.73571479330352
t = 2.680000000000002 || x = -6.364321093645097 || z = -96.89062412317931
t = 2.700000000000002 || x = -8.081788478871013 || z = -73.95800192066595
t = 2.720000000000002 || x = -9.291475123820007 || z = -46.37871464535844
t = 2.740000000000002 || x = -9.917378777779197 || z = -15.885571423314243
t = 2.760000000000002 || x = -9.920176250782555 || z = 15.605548507796897
t = 2.780000000000002 || x = -9.299693942828366 || z = 46.11607018010271
t = 2.800000000000002 || x = -8.09491861512778 || z = 73.72903600066141
t = 2.820000000000002 || x = -6.381547735174176 || z = 96.70954703568047
t = 2.840000000000002 || x = -4.267233314786264 || z = 113.61376522090194
t = 2.860000000000002 || x = -1.884818076439883 || z = 123.37962798286927
t = 2.880000000000002 || x = 0.6160110768128271 || z = 125.39357577975993
t = 2.900000000000002 || x = 3.078127873980628 || z = 119.52910018666961
t = 2.920000000000002 || x = 5.346838867921581 || z = 106.15469066605823
t = 2.940000000000002 || x = 7.279602739728403 || z = 86.11068083796641
t = 2.960000000000002 || x = 8.754986057150498 || z = 60.65644909540397
t = 2.980000000000002 || x = 9.680292803828532 || z = 31.39129102710149
t = 3.000000000000002 || x = 9.997388324395846 || z = 0.15393528562757197
t = 3.0200000000000022 || x = 9.686351776124408 || z = -31.092983656617385
t = 3.0400000000000023 || x = 8.76672761292434 || z = -60.386237291644186
t = 3.0600000000000023 || x = 7.296297479913596 || z = -85.8853517548587
t = 3.0800000000000023 || x = 5.367449688425842 || z = -105.98824346211738
t = 3.1000000000000023 || x = 3.101374383890397 || z = -119.43187640171065
t = 3.1200000000000023 || x = 0.6404491288682239 || z = -125.37161688537918
t = 3.1400000000000023 || x = -1.86070668241716 || z = -123.43430001255075
t = 3.1600000000000024 || x = -4.244946526717067 || z = -113.74167379936618
t = 3.1800000000000024 || x = -6.362470198926761 || z = -96.90274809232245
t = 3.2000000000000024 || x = -8.08023565942891 || z = -73.97552908849111
t = 3.2200000000000024 || x = -9.290317941497154 || z = -46.40054376980963
t = 3.2400000000000024 || x = -9.916689936395137 || z = -15.910330976350945
t = 3.2600000000000025 || x = -9.919999028274626 || z = 15.579414166832116
t = 3.2800000000000025 || x = -9.30003947222247 || z = 46.09020306371115
t = 3.3000000000000025 || x = -8.095765185167501 || z = 73.70506132605433
t = 3.3200000000000025 || x = -6.382842154542347 || z = 96.68897111324323
t = 3.3400000000000025 || x = -4.268894254198456 || z = 113.59788081386979
t = 3.3600000000000025 || x = -1.8867411786208659 || z = 123.36943308439379
t = 3.3800000000000026 || x = 0.6139466403330847 || z = 125.38971091051617
t = 3.4000000000000026 || x = 3.076051811216703 || z = 119.5318081525
t = 3.4200000000000026 || x = 5.344881616911306 || z = 106.16380130398261
t = 3.4400000000000026 || x = 7.277887273172877 || z = 86.12562170887212
t = 3.4600000000000026 || x = 8.753620156125976 || z = 60.67628145150934
t = 3.4800000000000026 || x = 9.679362286007423 || z = 31.41476879428713
t = 3.5000000000000027 || x = 9.99695165224104 || z = 0.17958335472469145
t = 3.5200000000000027 || x = 9.686436383816622 || z = -31.066776748651524
t = 3.5400000000000027 || x = 8.76732818279385 || z = -60.36111811382617
t = 3.5600000000000027 || x = 7.297376276660537 || z = -85.8628985289395
t = 3.5800000000000027 || x = 5.368938930123024 || z = -105.96986690392703
t = 3.6000000000000028 || x = 3.1031805007926336 || z = -119.41873108716155t = 3.6200000000000028 || x = 0.642458642442735 || z = -125.36452870992156
t = 3.640000000000003 || x = -1.8586200296214819 || z = -123.43371430171115
t = 3.660000000000003 || x = -4.24291383833202 || z = -113.74762733048627
t = 3.680000000000003 || x = -6.360619187571613 || z = -96.91486678527555
t = 3.700000000000003 || x = -8.078682622601423 || z = -73.99305151037849
t = 3.720000000000003 || x = -9.289160454698914 || z = -46.42236897675838
t = 3.740000000000003 || x = -9.916000722576026 || z = -15.935087686452409
t = 3.760000000000003 || x = -9.919821388772126 || z = 15.55328141561889
t = 3.780000000000003 || x = -9.300384566262204 || z = 46.064336184008525
t = 3.800000000000003 || x = -8.096611328846215 || z = 73.68108552020722
t = 3.820000000000003 || x = -6.384136183330893 || z = 96.66839276271696
t = 3.840000000000003 || x = -4.270554863352205 || z = 113.58199283445977
t = 3.860000000000003 || x = -1.8886640316143546 || z = 123.35923369370632
t = 3.880000000000003 || x = 0.611882356313842 || z = 125.38584091147294
t = 3.900000000000003 || x = 3.073975794607602 || z = 119.5345106732484
t = 3.920000000000003 || x = 5.342924302850664 || z = 106.17290652365541
t = 3.940000000000003 || x = 7.276171638323595 || z = 86.14055752878264
t = 3.960000000000003 || x = 8.752253992138487 || z = 60.69610944122617
t = 3.980000000000003 || x = 9.6784314270763 || z = 31.438243154026527
t = 4.000000000000003 || x = 9.996514582261216 || z = 0.2052291894027043
************************************************************************************************
Scilab
************************************************************************************************
/*
Estuos de Cálculo Numérico e programação em Scilab e linguagem Java
Autor: Rafael Alves Viana
Método de Runge-Kutta em Scilab e Oscilador Hamônico Simples - OMHS
data:
*/
f = 2; // ferquência em Hz
w = 2*%pi*f; // rad/s
// Derivadas, note; dy/dx = f1(x,y,u) = u, e du/dx = f2(x,y,u) = y - x*x - 2*x +
1
function [j0]=f1(t, x, z)
j0 = z;
endfunction
function [j1]=f2(t, x, z)
j1 = -w*w*x;
endfunction
/*
Condições iniciais, lembre-se:
dy(x = 0)/dx = y´(x=0) = u0 = 3/2 = 1.5
y(x = 0) = 1/2 = 0.5
São duas condições inisciais, pois temos uma equação iferencial de segunda or-
dem, logo duas conições
iniciais para encontarmos a resposta para o problema. Caso as condições iniciais
sejam diferentes
altere os valore para x0, y0 e t0.
*/
t0 = 0;
x0 = 10;
z0 = 0;
// Inicializano as novas variáveis justamente a partir das condições iniciais!.
t = x0;
x = x0;
z = z0;
// Paraâmetros para o méwtoo de Runge-Kutta de quarta ordem
N = 200; // quantiade de interações
h = 0.0002; // Passo
// No loop for tem-se -----> t = tempo
for t=0:0.01:N
// Runge-Kutta de quarta ordem
k11 = h*f1(t,x,z);
k12 = h*f2(t,x,z);
k21 = h*f1(t + (h/2),x + (k11/2),z + (k12/2));
k22 = h*f2(t + (h/2),x + (k11/2),z + (k12/2));
k31 = h*f1(t + (h/2),x + (k21/2),z + (k22/2));
k32 = h*f2(t + (h/2),x + (k21/2),z + (k22/2));
k41 = h*f1(t + h,x + k31,z + k32);
k42 = h*f2(t + h,x + k31,z + k32);
x = x + ((k11 + 2*k21 + 2*k31 + k41)/6);
z = z + ((k12 + 2*k22 + 2*k32 + k42)/6);
t = t + h;
//Saída
printf("t = %f || x = %f || z = %f\n",t,x,z);
//Gráfico
plot(t,x,'-*')// tempo x posição
//plot(t,z,'-o') // tempo x velocidade
//plot(x,z,'-x')// espaço de fase posição x velocidade
xtitle("Gráfico da Solução: pontos (t,x) cálculaos numéricamente via Runge-
Kutta de Quarta Ordem");
xgrid(0.05);
end
*********************************** Saída dos dados ***********************************
t = 0.000200 || x = 9.999968 || z = -0.315827
t = 0.010200 || x = 9.999874 || z = -0.631652
t = 0.020200 || x = 9.999716 || z = -0.947473
t = 0.030200 || x = 9.999495 || z = -1.263288
t = 0.040200 || x = 9.999210 || z = -1.579095
t = 0.050200 || x = 9.998863 || z = -1.894892
t = 0.060200 || x = 9.998452 || z = -2.210677
t = 0.070200 || x = 9.997979 || z = -2.526448
t = 0.080200 || x = 9.997442 || z = -2.842204
t = 0.090200 || x = 9.996842 || z = -3.157941
t = 0.100200 || x = 9.996179 || z = -3.473658
t = 0.110200 || x = 9.995452 || z = -3.789354
t = 0.120200 || x = 9.994663 || z = -4.105025
t = 0.130200 || x = 9.993810 || z = -4.420670
t = 0.140200 || x = 9.992895 || z = -4.736288
t = 0.150200 || x = 9.991916 || z = -5.051876
t = 0.160200 || x = 9.990874 || z = -5.367431
t = 0.170200 || x = 9.989769 || z = -5.682953
t = 0.180200 || x = 9.988601 || z = -5.998439
t = 0.190200 || x = 9.987370 || z = -6.313887
t = 0.200200 || x = 9.986075 || z = -6.629295
t = 0.210200 || x = 9.984718 || z = -6.944662
t = 0.220200 || x = 9.983297 || z = -7.259984
t = 0.230200 || x = 9.981814 || z = -7.575261
t = 0.240200 || x = 9.980267 || z = -7.890489
t = 0.250200 || x = 9.978658 || z = -8.205668
t = 0.260200 || x = 9.976985 || z = -8.520795
t = 0.270200 || x = 9.975249 || z = -8.835869
t = 0.280200 || x = 9.973451 || z = -9.150886
t = 0.290200 || x = 9.971589 || z = -9.465846
t = 0.300200 || x = 9.969664 || z = -9.780745
t = 0.310200 || x = 9.967677 || z = -10.095583
t = 0.320200 || x = 9.965626 || z = -10.410358
t = 0.330200 || x = 9.963513 || z = -10.725066
t = 0.340200 || x = 9.961336 || z = -11.039707
t = 0.350200 || x = 9.959097 || z = -11.354278
t = 0.360200 || x = 9.956794 || z = -11.668777
t = 0.370200 || x = 9.954429 || z = -11.983203
t = 0.380200 || x = 9.952001 || z = -12.297553
t = 0.390200 || x = 9.949510 || z = -12.611825
t = 0.400200 || x = 9.946956 || z = -12.926018
t = 0.410200 || x = 9.944340 || z = -13.240129
t = 0.420200 || x = 9.941660 || z = -13.554156
t = 0.430200 || x = 9.938918 || z = -13.868098
t = 0.440200 || x = 9.936113 || z = -14.181952
t = 0.450200 || x = 9.933245 || z = -14.495716
t = 0.460200 || x = 9.930315 || z = -14.809389
t = 0.470200 || x = 9.927322 || z = -15.122968
t = 0.480200 || x = 9.924266 || z = -15.436452
t = 0.490200 || x = 9.921147 || z = -15.749839
t = 0.500200 || x = 9.917966 || z = -16.063126
t = 0.510200 || x = 9.914722 || z = -16.376311
t = 0.520200 || x = 9.911415 || z = -16.689393
t = 0.530200 || x = 9.908046 || z = -17.002369
t = 0.540200 || x = 9.904614 || z = -17.315239
t = 0.550200 || x = 9.901120 || z = -17.627998
t = 0.560200 || x = 9.897563 || z = -17.940647
t = 0.570200 || x = 9.893944 || z = -18.253182
t = 0.580200 || x = 9.890262 || z = -18.565602
t = 0.590200 || x = 9.886517 || z = -18.877904
t = 0.600200 || x = 9.882711 || z = -19.190088
t = 0.610200 || x = 9.878841 || z = -19.502150
t = 0.620200 || x = 9.874910 || z = -19.814089
t = 0.630200 || x = 9.870916 || z = -20.125902
t = 0.640200 || x = 9.866859 || z = -20.437589
t = 0.650200 || x = 9.862741 || z = -20.749146
t = 0.660200 || x = 9.858560 || z = -21.060573
t = 0.670200 || x = 9.854317 || z = -21.371866
t = 0.680200 || x = 9.850011 || z = -21.683025
t = 0.690200 || x = 9.845643 || z = -21.994046
t = 0.700200 || x = 9.841213 || z = -22.304929
t = 0.710200 || x = 9.836721 || z = -22.615670
t = 0.720200 || x = 9.832167 || z = -22.926269
t = 0.730200 || x = 9.827551 || z = -23.236723
t = 0.740200 || x = 9.822873 || z = -23.547030
t = 0.750200 || x = 9.818132 || z = -23.857189
t = 0.760200 || x = 9.813330 || z = -24.167197
t = 0.770200 || x = 9.808465 || z = -24.477052
t = 0.780200 || x = 9.803539 || z = -24.786752
t = 0.790200 || x = 9.798551 || z = -25.096296
t = 0.800200 || x = 9.793500 || z = -25.405682
t = 0.810200 || x = 9.788388 || z = -25.714907
t = 0.820200 || x = 9.783214 || z = -26.023969
t = 0.830200 || x = 9.777979 || z = -26.332867
t = 0.840200 || x = 9.772681 || z = -26.641599
t = 0.850200 || x = 9.767322 || z = -26.950163
t = 0.860200 || x = 9.761901 || z = -27.258556
t = 0.870200 || x = 9.756419 || z = -27.566777
t = 0.880200 || x = 9.750874 || z = -27.874824
t = 0.890200 || x = 9.745269 || z = -28.182695
t = 0.900200 || x = 9.739601 || z = -28.490388
t = 0.910200 || x = 9.733873 || z = -28.797901
t = 0.920200 || x = 9.728082 || z = -29.105232
t = 0.930200 || x = 9.722231 || z = -29.412379
t = 0.940200 || x = 9.716317 || z = -29.719340
t = 0.950200 || x = 9.710343 || z = -30.026114
t = 0.960200|| x = 9.704307 || z = -30.332698
t = 0.970200 || x = 9.698210 || z = -30.639091
t = 0.980200 || x = 9.692051 || z = -30.945289
t = 0.990200 || x = 9.685832 || z = -31.251293
t = 1.000200 || x = 9.679551 || z = -31.557099
t = 1.010200 || x = 9.673209 || z = -31.862706
t = 1.020200 || x = 9.666806 || z = -32.168111
t = 1.030200 || x = 9.660342 || z = -32.473313
t = 1.040200 || x = 9.653816 || z = -32.778310
t = 1.050200 || x = 9.647230 || z = -33.083100
t = 1.060200 || x = 9.640583 || z = -33.387682
t = 1.070200 || x = 9.633875 || z = -33.692052
t = 1.080200 || x = 9.627106 || z = -33.996209
t = 1.090200 || x = 9.620277 || z = -34.300152
t = 1.100200 || x = 9.613386 || z = -34.603878
t = 1.110200 || x = 9.606435 || z = -34.907385
t = 1.120200 || x = 9.599423 || z = -35.210672
t = 1.130200 || x = 9.592351 || z = -35.513737
t = 1.140200 || x = 9.585218 || z = -35.816577
t = 1.150200 || x = 9.578024 || z = -36.119191
t = 1.160200 || x = 9.570770 || z = -36.421577
t = 1.170200 || x = 9.563456 || z = -36.723732
t = 1.180200 || x = 9.556081 || z = -37.025656
t = 1.190200 || x = 9.548645 || z = -37.327346
t = 1.200200 || x = 9.541150 || z = -37.628800
t = 1.210200 || x = 9.533594 || z = -37.930017
t = 1.220200 || x = 9.525978 || z = -38.230993
t = 1.230200 || x = 9.518302 || z = -38.531729
t = 1.240200 || x = 9.510565 || z = -38.832221
t = 1.250200 || x = 9.502769 || z = -39.132467
t = 1.260200 || x = 9.494912 || z = -39.432467
t = 1.270200 || x = 9.486996 || z = -39.732217
t = 1.280200 || x = 9.479019 || z = -40.031717
t = 1.290200 || x = 9.470983 || z = -40.330963
t = 1.300200 || x = 9.462887 || z = -40.629955
t = 1.310200 || x = 9.454731 || z = -40.928691
t = 1.320200 || x = 9.446515 || z = -41.227167
t = 1.330200 || x = 9.438240 || z = -41.525383
t = 1.340200 || x = 9.429905 || z = -41.823337
t = 1.350200 || x = 9.421511 || z = -42.121027
t = 1.360200 || x = 9.413057 || z = -42.418451
t = 1.370200 || x = 9.404544 || z = -42.715607
t = 1.380200 || x = 9.395971 || z = -43.012493
t = 1.390200 || x = 9.387339 || z = -43.309107
t = 1.400200 || x = 9.378647 || z = -43.605448
t = 1.410200 || x = 9.369896 || z = -43.901513
t = 1.420200 || x = 9.361087 || z = -44.197301
t = 1.430200 || x = 9.352218 || z = -44.492810
t = 1.440200 || x = 9.343289 || z = -44.788038
t = 1.450200 || x = 9.334302 || z = -45.082982
t = 1.460200 || x = 9.325256 || z = -45.377643
t = 1.470200 || x = 9.316151 || z = -45.672016
t = 1.480200 || x = 9.306987 || z = -45.966101
t = 1.490200 || x = 9.297765 || z = -46.259896
t = 1.500200 || x = 9.288484 || z = -46.553398
t = 1.510200 || x = 9.279144 || z = -46.846606
t = 1.520200 || x = 9.269745 || z = -47.139519
t = 1.530200 || x = 9.260288 || z = -47.432134
t = 1.540200 || x = 9.250772 || z = -47.724449
t = 1.550200 || x = 9.241198 || z = -48.016462
t = 1.560200 || x = 9.231566 || z = -48.308173
t = 1.570200 || x = 9.221875 || z = -48.599578
t = 1.580200 || x = 9.212126 || z = -48.890676
t = 1.590200 || x = 9.202318 || z = -49.181465
t = 1.600200 || x = 9.192453 || z = -49.471944
t = 1.610200 || x = 9.182530 || z = -49.762110
t = 1.620200 || x = 9.172548 || z = -50.051962
t = 1.630200 || x = 9.162509 || z = -50.341498
t = 1.640200 || x = 9.152412 || z = -50.630716
t = 1.650200 || x = 9.142257 || z = -50.919614
t = 1.660200 || x = 9.132044 || z = -51.208190
t = 1.670200 || x = 9.121773 || z = -51.496443
t = 1.680200 || x = 9.111445 || z = -51.784371
t = 1.690200 || x = 9.101060 || z = -52.071971
t = 1.700200 || x = 9.090617 || z = -52.359243
t = 1.710200 || x = 9.080116 || z = -52.646184
t = 1.720200 || x = 9.069558 || z = -52.932792
t = 1.730200 || x = 9.058943 || z = -53.219066
t = 1.740200 || x = 9.048271 || z = -53.505004
t = 1.750200 || x = 9.037541 || z = -53.790604
t = 1.760200 || x = 9.026754 || z = -54.075864
t = 1.770200 || x = 9.015911 || z = -54.360782
t = 1.780200 || x = 9.005010 || z = -54.645357
t = 1.790200 || x = 8.994053 || z = -54.929587
t = 1.800200 || x = 8.983038 || z = -55.213470
t = 1.810200 || x = 8.971967 || z = -55.497004
t = 1.820200 || x = 8.960839 || z = -55.780188
t = 1.830200 || x = 8.949655 || z = -56.063019
t = 1.840200 || x = 8.938414 || z = -56.345497
t = 1.850200 || x = 8.927117 || z = -56.627618
t = 1.860200 || x = 8.915763 || z = -56.909382
t = 1.870200 || x = 8.904353 || z = -57.190786
t = 1.880200 || x = 8.892887 || z = -57.471829
t = 1.890200 || x = 8.881364 || z = -57.752509
t = 1.900200 || x = 8.869786 || z = -58.032824
t = 1.910200 || x = 8.858151 || z = -58.312772
t = 1.920200 || x = 8.846461 || z = -58.592352
t = 1.930200 || x = 8.834714 || z = -58.871562
t = 1.940200 || x = 8.822912 || z = -59.150401
t = 1.950200 || x = 8.811054 || z = -59.428865
t = 1.960200 || x = 8.799141 || z = -59.706954
t = 1.970200 || x = 8.787172 || z = -59.984666
t = 1.980200 || x = 8.775147 || z = -60.262000
t = 1.990200 || x = 8.763067 || z = -60.538952
t = 2.000200 || x = 8.750931 || z = -60.815522
t = 2.010200 || x = 8.738741 || z = -61.091708
t = 2.020200 || x = 8.726495 || z = -61.367508
t = 2.030200 || x = 8.714194 || z = -61.642921
t = 2.040200 || x = 8.701838 || z = -61.917944
t = 2.050200 || x = 8.689426 || z = -62.192576
t = 2.060200 || x = 8.676961 || z = -62.466815
t = 2.070200 || x = 8.664440 || z = -62.740660
t = 2.080200 || x = 8.651864 || z = -63.014108
t = 2.090200 || x = 8.639234 || z = -63.287158
t = 2.100200 || x = 8.626549 || z = -63.559808

Continue navegando