АвтоАвтоматизацияАрхитектураАстрономияАудитБиологияБухгалтерияВоенное делоГенетикаГеографияГеологияГосударствоДомДругоеЖурналистика и СМИИзобретательствоИностранные языкиИнформатикаИскусствоИсторияКомпьютерыКулинарияКультураЛексикологияЛитератураЛогикаМаркетингМатематикаМашиностроениеМедицинаМенеджментМеталлы и СваркаМеханикаМузыкаНаселениеОбразованиеОхрана безопасности жизниОхрана ТрудаПедагогикаПолитикаПравоПриборостроениеПрограммированиеПроизводствоПромышленностьПсихологияРадиоРегилияСвязьСоциологияСпортСтандартизацияСтроительствоТехнологииТорговляТуризмФизикаФизиологияФилософияФинансыХимияХозяйствоЦеннообразованиеЧерчениеЭкологияЭконометрикаЭкономикаЭлектроникаЮриспунденкция
|
Текст программы
#include <iostream>
#define nmax 100
using namespace std;
class diffur
{
public:
int n;
float z[100], zn[100];
float zp[100];
float A[100][100];
float z0[100], f0[100];
float h;
float tfinal;
void f (float t,float y[100],float yp[100])
{
yp[1]= A[1][1]*y[1] + A[1][2]*y[2] + A[1][3]*y[3] + f0[1];
yp[2]= A[2][1]*y[1] + A[2][2]*y[2] + A[2][3]*y[3] + f0[2];
yp[3]= A[3][1]*y[1] + A[3][2]*y[2] + A[3][3]*y[3] + f0[3];
}
void SetBeginData()
{
n = 3;
A[1][1] = -6; A[1][2] = -2; A[1][3] = -12; f0[1] = 16; z0[1] = 2;
A[2][1] = -16; A[2][2] = -17; A[2][3] = 17; f0[2] = -18; z0[2] = 0;
A[3][1] = 44; A[3][2] = 3; A[3][3] = -45; f0[3] = 4; z0[3] = -2;
h = 2 / NormMatrix(3, A);
tfinal = 4.0;
}
float NormMatrix(int n,float A[100][100])
{
int i, j;
float Sum, FullSum;
FullSum = 0;
for (i=1;i<=n;i++)
{
Sum = 0;
for (j=1;j<=n;j++)
{
Sum = Sum + (A[i][j])*(A[i][j]);
}
FullSum = FullSum + Sum;
}
return sqrt(FullSum);
}
void IntegrateMethod()
{
int i, j;
float t, tout;
FILE *f1,*f2,*f3,*f4;
f1=fopen("t.txt","w");
f2=fopen("y1.txt","w");
f3=fopen("y2.txt","w");
f4=fopen("y3.txt","w");
t = 0;
tout = 1.0;
for (i=1;i<=n;i++)
z[i] = z0[i];
while (t < tout + h)
{
fprintf(f1,"%f\n",t);
fprintf(f2,"%f\n",z[1]);
fprintf(f3,"%f\n",z[2]);
fprintf(f4,"%f\n",z[3]);
f(t, z, zp);
for (i=1;i<=n;i++)
zn[i] = z[i] + h/4 * zp[i];
f(t+h/4, zn, zp);
for (i=1;i<=n;i++)
z[i] = z[i] + h * (-zp[i]+2*zp[i]);
t = t + h;
}
fclose(f1);
fclose(f2);
fclose(f3);
fclose(f4);
}
};
void main()
{
diffur a;
a.SetBeginData();
a.IntegrateMethod();
}
Таблица полученная своим методом
t
| y1
| y2
| y3
| 0.000000
| 2.000000
| 0.000000
| -2.000000
| 0.028318
| 2.355061
| -1.561975
| 1.708457
| 0.056637
| 1.871906
| -1.425509
| 2.074405
| 0.084955
| 1.425995
| -1.120818
| 1.711683
| 0.113273
| 1.161554
| -0.949747
| 1.357055
| 0.141591
| 1.036501
| -0.897059
| 1.141433
| 0.169910
| 0.989636
| -0.903665
| 1.036893
| 0.198228
| 0.978828
| -0.929095
| 0.996070
| 0.226546
| 0.981384
| -0.954298
| 0.985335
| 0.254864
| 0.987051
| -0.973147
| 0.986203
| 0.283183
| 0.992068
| -0.985360
| 0.990125
| 0.311501
| 0.995559
| -0.992544
| 0.993846
| 0.339819
| 0.997694
| -0.996458
| 0.996509
| 0.368138
| 0.998887
| -0.998447
| 0.998167
| 0.396456
| 0.999504
| -0.999389
| 0.999105
| 0.424774
| 0.999801
| -0.999800
| 0.999596
| 0.453092
| 0.999933
| -0.999961
| 0.999835
| 0.481411
| 0.999985
| -1.000012
| 0.999942
| 0.509729
| 1.000003
| -1.000021
| 0.999986
| 0.538047
| 1.000006
| -1.000018
| 1.000001
| 0.566366
| 1.000005
| -1.000012
| 1.000004
| 0.594684
| 1.000004
| -1.000007
| 1.000004
| 0.623002
| 1.000002
| -1.000004
| 1.000003
| 0.651320
| 1.000001
| -1.000002
| 1.000002
| 0.679639
| 1.000001
| -1.000001
| 1.000001
| 0.707957
| 1.000000
| -1.000000
| 1.000000
| 0.736275
| 1.000000
| -1.000000
| 1.000000
| 0.764594
| 1.000000
| -1.000000
| 1.000000
| 0.792912
| 1.000000
| -1.000000
| 1.000000
| 0.821230
| 1.000000
| -1.000000
| 1.000000
| 0.849548
| 1.000000
| -1.000000
| 1.000000
| 0.877867
| 1.000000
| -1.000000
| 1.000000
| 0.906185
| 1.000000
| -1.000000
| 1.000000
| 0.934503
| 1.000000
| -1.000000
| 1.000000
| 0.962822
| 1.000000
| -1.000000
| 1.000000
| 0.991140
| 1.000000
| -1.000000
| 1.000000
| 1.019458
| 1.000000
| -1.000000
| 1.000000
|
Таблица полученная методом RKF45
t
| y1
| y2
| y3
| 0.00000000000000
| 2.00000000000000
| 0.00000000000000
| -2.00000000000000
| 0.02831827358943
| 2.19250798734663
| -1.21894463346687
| 1.00631835488928
| 0.05663654717886
| 1.87613663048469
| -1.32211809907946
| 1.70091270162824
| 0.08495482076829
| 1.53236733772736
| -1.17688199803625
| 1.65141291898499
| 0.11327309435772
| 1.28410992603073
| -1.04304215807577
| 1.44111018805772
| 0.14159136794715
| 1.13327324695288
| -0.96864977780615
| 1.25485184375449
| 0.16990964153658
| 1.05193300764476
| -0.94145334497775
| 1.12990791391046
| 0.19822791512601
| 1.01285409946163
| -0.94068349865759
| 1.05744202567539
| 0.22654618871544
| 0.99677543859682
| -0.95100629399660
| 1.01995507664836
| 0.25486446230487
| 0.99196547489605
| -0.96378614924569
| 1.00283651140188
| 0.28318273589430
| 0.99198618046730
| -0.97512956579567
| 0.99638782186059
| 0.31150100948373
| 0.99363077340254
| -0.98382719205365
| 0.99493828450572
| 0.33981928307316
| 0.99547935009621
| -0.98993506107207
| 0.99548445575643
| 0.36813755666259
| 0.99701485307807
| -0.99396773188895
| 0.99658905744183
| 0.39645583025202
| 0.99813067775742
| -0.99650591762903
| 0.99765252542669
| 0.42477410384145
| 0.99887872987366
| -0.99804090884649
| 0.99848341580392
| 0.45309237743088
| 0.99935232793465
| -0.99893686144356
| 0.99906655089946
| 0.48141065102031
| 0.99963888522937
| -0.99944269973483
| 0.99944830091561
| 0.50972892460974
| 0.99980564430035
| -0.99971903321224
| 0.99968561365358
| 0.53804719819917
| 0.99989926010742
| -0.99986487858384
| 0.99982701803705
| 0.56636547178860
| 0.99994998530461
| -0.99993896247978
| 0.99990817577925
| 0.59468374537803
| 0.99997646538563
| -0.99997491428987
| 0.99995313251598
| 0.62300201896746
| 0.99998971979290
| -0.99999135311063
| 0.99997716007527
| 0.65132029255689
| 0.99999602134859
| -0.99999823942988
| 0.99998951515964
| 0.67963856614632
| 0.99999881496055
| -1.00000070730435
| 0.99999558938130
| 0.70795683973575
| 0.99999992426062
| -1.00000129146162
| 0.99999841035044
| 0.73627511332518
| 1.00000027648311
| -1.00000117723400
| 0.99999961822851
| 0.76459338691461
| 1.00000032114124
| -1.00000087837180
| 1.00000006878000
| 0.79291166050404
| 1.00000026273559
| -1.00000059084292
| 1.00000018957334
| 0.82122993409347
| 1.00000018622889
| -1.00000037130809
| 1.00000018364872
| 0.84954820768290
| 1.00000012137070
| -1.00000022159577
| 1.00000014073057
| 0.87786648127233
| 1.00000007455632
| -1.00000012658531
| 1.00000009622869
| 0.90618475486176
| 1.00000004368401
| -1.00000006943338
| 1.00000006120931
| 0.93450302845119
| 1.00000002455017
| -1.00000003655517
| 1.00000003689936
| 0.96282130204062
| 1.00000001325512
| -1.00000001839771
| 1.00000002127383
| 0.99113957563005
| 1.00000000686352
| -1.00000000876939
| 1.00000001177626
| 1.01945784921948
| 1.00000000338875
| -1.00000000388361
| 1.00000000626113
| 1.04777612280891
| 1.00000000157604
| -1.00000000153050
| 1.00000000318731
| 1.07609439639834
| 1.00000000067310
| -1.00000000047284
| 1.00000000154152
| 1.10441266998777
| 1.00000000024825
| -1.00000000004529
| 1.00000000069710
| 1.13273094357720
| 1.00000000006359
| -0.99999999990490
| 1.00000000028473
| 1.16104921716663
| 0.99999999999318
| -0.99999999988325
| 1.00000000009575
| 1.18936749075606
| 0.99999999997324
| -0.99999999990260
| 1.00000000001687
| 1.21768576434549
| 0.99999999997312
| -0.99999999993015
| 0.99999999998909
| 1.24600403793492
| 0.99999999997906
| -0.99999999995408
| 0.99999999998305
| 1.27432231152435
| 0.99999999998553
| -0.99999999997158
| 0.99999999998498
| 1.30264058511378
| 0.99999999999072
| -0.99999999998323
| 0.99999999998891
| 1.33095885870321
| 0.99999999999436
| -0.99999999999051
| 0.99999999999257
| 1.35927713229264
| 0.99999999999673
| -0.99999999999483
| 0.99999999999534
| 1.38759540588207
| 0.99999999999817
| -0.99999999999730
| 0.99999999999722
| 1.41591367947150
| 0.99999999999902
| -0.99999999999865
| 0.99999999999841
| 1.44423195306093
| 0.99999999999950
| -0.99999999999936
| 0.99999999999913
| 1.47255022665036
| 0.99999999999975
| -0.99999999999972
| 0.99999999999954
| 1.50086850023979
| 0.99999999999989
| -0.99999999999989
| 0.99999999999977
| 1.52918677382922
| 0.99999999999995
| -0.99999999999997
| 0.99999999999989
| 1.55750504741865
| 0.99999999999998
| -1.00000000000000
| 0.99999999999995
| 1.58582332100808
| 1.00000000000000
| -1.00000000000001
| 0.99999999999998
| 1.61414159459751
| 1.00000000000000
| -1.00000000000001
| 0.99999999999999
| 1.64245986818694
| 1.00000000000000
| -1.00000000000001
| 1.00000000000000
| 1.67077814177637
| 1.00000000000000
| -1.00000000000001
| 1.00000000000000
| 1.69909641536580
| 1.00000000000000
| -1.00000000000000
| 1.00000000000000
|
1 | 2 | Поиск по сайту:
|