-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathapp.py
1787 lines (1585 loc) · 81 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from flask import Flask, render_template, url_for, request, redirect, jsonify
from methods.PolynomialInterpolation import Newton, LaGrange
from methods.Bezier import bezier_curve_bin
from methods.SplineInterpolation import linear_spline, quad_spline,cubic_spline, get_interval_list
from methods.Regression import Nonlinear_Regression, TrueError, Curve_Family_Detective, Linearized_Regression, Surface_Fit_Beta, PointsFor3DSF, zEvalList, SurfaceInt
from methods.Differentiation import TableDeriv, FuncDeriv
from methods.NewtonCotes import Trapezoidal_Integ, Trapezoidal_error, Trapezoidal_Double_Integ, single_mixe_rule, double_mixed_rule, triple_mixed_rule, Trapezoidal_Triple_Integ
from methods.Romberg import RombergRule
from methods.Gauss_Quadrature import myfun, Exact
from methods.ODE_Kutta import rungeKutta,TrueDifferentials,TrueErrorr
from methods.ODE_Adams import ode_adams_backward_difference
from methods.ODE_milne import milne
from methods.RegularPDE import Open_Region, Closed_Region
from methods.PDE_Solve import Grid, PDE_Solver, boundry , point
from methods.LinearSystems import solve_linear_systems
from methods.NewtonRaphson import Newton_Raphson
from methods.FixedPoint import FixedPointIteration
from methods.Eigenvalue import solve_Eigenvalue
from methods.ODE_EulerAndHeun import func_xyzt,Solve_Euler ,Solve_Heun
from methods.BilinearInterpolation import Surface_Interpolation
from methods.LeastAbsoluteErrors import LeastAbsoluteDeviations, LeastSquares,CorrelationCoefficients, Numpify, Angulus, ZeroDerivativeCheck
from methods.LogCosh import minLogCoshLoss, RegressionErrors
import numpy as np
app = Flask(__name__)
app.static_folder = 'static'
app.config['SECRET_KEY'] = 'edcb30ed4a6a5b467a2ed529ed889dbf'
@app.route("/")
@app.route("/home")
def home():
return render_template('Home.html')
@app.route("/home-dynamic")
def homeDynamic():
return render_template('home-dynamic.html')
@app.route("/Credits")
def Credits():
return render_template('Credits.html', title='Credits', css="Credits.css", wing="Neon Green Header.svg", logo="Logo.svg")
@app.route("/Contact")
def Contact():
return render_template('Contact.html', title='Contact', css="Contact.css", wing="Neon Green Header.svg", logo="Logo.svg")
@app.route("/PolynomialInterpolation", methods=['GET', 'POST'])
def PolynomialInterpolation():
PolynomialFunction = ""
if request.method == 'POST':
Method = ''
error = ''
Degree = -1
NumPoints = 0
X_Points = []
Y_Points = []
if 'Method' in request.form:
Method = request.form['Method']
if Method=="Newton" and (request.form['Degree']) :
try:
Degree = int(request.form['Degree'])
except:
pass
for i in range(20):
if request.form["X_" + str(i)] and request.form["Y_" + str(i)]:
try:
x_temp = float(request.form["X_" + str(i)])
if not(x_temp in X_Points):
X_Points.append(float(request.form["X_" + str(i)]))
Y_Points.append(float(request.form["Y_" + str(i)]))
except:
pass
NumPoints = len(X_Points)
PolynomialDerivativeFunction = ''
ResidualError = ''
PolynomialFunction = ''
ParametricX = ''
ParametricY = ''
X_val = 0
if not(Method):
error = 'Chose a Method'
PolynomialFunction = 'Chose a Method'
elif Degree < 0 and Method =='Newton':
error = 'Invalid Degree'
PolynomialFunction = 'Invalid Degree'
elif Method=='Lagrange' and NumPoints > 0 :
Y_val, PolynomialFunction = LaGrange(X_Points, Y_Points, NumPoints, X_val)
ParametricX, ParametricY = bezier_curve_bin(NumPoints, X_Points, Y_Points)
elif Method=='Newton' and NumPoints > Degree:
X_diff_val = 0
DT, Y_val, PolynomialFunction, Y_diff_val, PolynomialDerivativeFunction, ResidualError = Newton(X_Points, Y_Points, NumPoints, X_val, Degree)
ParametricX ,ParametricY = bezier_curve_bin(NumPoints,X_Points,Y_Points)
else:
error = 'Missing Points'
return render_template('PolynomialInterpolation.html', url="vdBtRSCF_kA", title='Polynomial Interpolation',
css="PolynomialInterpolation.css", wing="CF Header.png", logo="Logo.svg", Method = Method,
PolynomialFunction = PolynomialFunction , PolynomialDerivativeFunction= PolynomialDerivativeFunction,
ResidualError = ResidualError, ParametricX=ParametricX,ParametricY=ParametricY, error = error)
else:
return render_template('PolynomialInterpolation.html', url="vdBtRSCF_kA", title='Polynomial Interpolation', css="PolynomialInterpolation.css", wing="CF Header.png", logo="Logo.svg", PolynomialFunction = PolynomialFunction)
@app.route("/SplineInterpolation", methods=['GET', 'POST'])
def SplineInterpolation():
if request.method == 'POST':
Numbers =[]
NumPoints = 0
while (request.form['x_coordinates'+str(NumPoints)]) and (request.form['y_coordinates'+str(NumPoints)]):
try:
Numbers.append([float((request.form['x_coordinates'+str(NumPoints)])),float((request.form['y_coordinates'+str(NumPoints)]))])
NumPoints +=1
except:
pass
if NumPoints > 1:
LinearSpline = linear_spline(NumPoints,Numbers)
IntervalList = get_interval_list(NumPoints,Numbers)
QuadraticSpline = quad_spline(NumPoints,Numbers)
CubicSpline = cubic_spline(NumPoints,Numbers)
return render_template('SplineInterpolation.html', title='Spline Interpolation', css="SplineInterpolation.css",
wing="CF Header.png", logo="Logo.svg",NumPoints = NumPoints-1,
IntervalList = IntervalList, LinearSpline = LinearSpline,
QuadraticSpline = QuadraticSpline, CubicSpline = CubicSpline)
else:
return render_template('SplineInterpolation.html', title='Spline Interpolation',
css="SplineInterpolation.css", wing="CF Header.png", logo="Logo.svg",
eq="",error = 'Missing Points')
else:
return render_template('SplineInterpolation.html', title='Spline Interpolation', css="SplineInterpolation.css", wing="CF Header.png", logo="Logo.svg" , eq="")
@app.route("/BilinearInterpolation", methods=['GET', 'POST'])
def BilinearInterpolation():
if request.method == 'POST':
points = []
Z = []
plane=''
_Z=''
x_val1=request.form['xinput']
y_val1=request.form['yinput']
x_val=0
y_val=0
if x_val1 and y_val1:
try:
x_val=float(x_val1)
y_val=float(y_val1)
except:
pass
for i in range(25):
x = request.form['x' + str(i)]
y = request.form['y' + str(i)]
z = request.form['z' + str(i)]
if x and y and z:
try:
points.append([float(x), float(y)])
Z.append(float(z))
except:
pass
try:
np_points=np.array(points)
np_Z=np.array(Z)
surface = Surface_Interpolation(np_points,np_Z )
plane=surface.GetPlane_of_P(x_val,y_val)
Surf, GriX, GriY, GriZ = surface.BiLinearInt()
GriZ = GriZ.transpose()
x1 = list(GriX)
y1 = list(GriY)
z1 = []
_Z=-1*plane[3]-x_val*plane[0]-y_val*plane[1]
plane = list(plane)
plane.append(0)
plane.append(0)
if plane[2]:
_Z = np.round(_Z/plane[2],5)
plane[4] = np.round(-1*plane[0]/plane[2],5)
plane[5] = np.round(-1*plane[1]/plane[2],5)
plane = np.round(plane, 5)
for i in range(np.shape(GriZ)[0]):
z1.append(list(GriZ[i]))
except:
return render_template('BI.html', title='Bilinear Interpolation', css="BI.css", wing="CF Header.png", logo="Logo.svg" , eq="",plane=[1,1,1,1],_Z="")
return render_template('BI.html', title='Bilinear Interpolation', css="BI.css", wing="CF Header.png", logo="Logo.svg", eq="",x1 = x1, y1 = y1, z1 = z1,function=surface.GetPlane_of_P,plane=plane,Z=_Z)
else:
return render_template('BI.html', title='Bilinear Interpolation', css="BI.css", wing="CF Header.png", logo="Logo.svg" , eq="",plane=[1,1,1,1],_Z="",z="")
@app.route("/LeastSquareReg", methods=['GET', 'POST'])
def LeastSquareReg():
if request.method == 'POST':
Method = ''
error = ''
if 'Method' in request.form:
Method = request.form['Method']
if Method == 'Nonlinear':
Equation = request.form['Nonlinear_Equation']
i = 0
xdata = []
ydata = []
while (request.form['x_coordinates' + str(i)]!='' and request.form['y_coordinates' + str(i)]!=''):
try:
xdata.append(float(request.form['x_coordinates' + str(i)]))
ydata.append(float(request.form['y_coordinates' + str(i)]))
except:
pass
i += 1
if len(xdata)>=3:
try:
result, Error = Nonlinear_Regression(xdata, ydata, Equation, 12)
TrueErr = TrueError(ydata, 12)
r = round((abs(Error-TrueErr)/TrueErr)**0.5,12)
except:
error = "Invalid Inputs"
result = "Invalid Inputs"
Error = '...'
TrueErr = '...'
r = '...'
elif len(xdata) == 0:
error = 'Missing Points'
result = "Missing Points"
Error = '...'
TrueErr = '...'
r = '...'
else:
error = "The data set is too small"
result = "The data set is too small"
Error = '...'
TrueErr = '...'
r = '...'
return render_template('LeastSquareReg.html', url="gr-a8q7EDbY", title='Least Square Reg.', css="LeastSquareReg.css", wing="CF Header.png", logo="Logo.svg", Method=Method, results=result, Error=Error, TrueErr=TrueErr, r=r, error = error)
elif Method == 'Linearized':
i = 0
xdata = []
ydata = []
while (request.form['x_coordinates' + str(i)]!='' and request.form['y_coordinates' + str(i)]!=''):
try:
xdata.append(float(request.form['x_coordinates' + str(i)]))
ydata.append(float(request.form['y_coordinates' + str(i)]))
except:
pass
i += 1
j = 0
Fdata = [request.form['Abdullah_Knows_It_All']]
while request.form['term' + str(j)]:
Fdata.append(request.form['term' + str(j)])
j += 1
try:
LHS, RHS, Constants, Sr = Linearized_Regression(xdata, ydata, Fdata, 12)
except:
error = "Invalid Inputs"
result = "Invalid Inputs"
Error = '...'
TrueErr = '...'
r = '...'
return render_template('LeastSquareReg.html', url="gr-a8q7EDbY", title='Least Square Reg.',
css="LeastSquareReg.css", wing="CF Header.png", logo="Logo.svg", Method=Method,
results=result, Error=Error, TrueErr=TrueErr, r=r, error = error)
if ydata and xdata and LHS !="" :
TrueErr = TrueError(ydata, 4)
r = round((abs(Sr-TrueErr)/TrueErr)**0.5,12)
return render_template('LeastSquareReg.html', url="gr-a8q7EDbY", title='Least Square Reg.',
css="LeastSquareReg.css", wing="CF Header.png", logo="Logo.svg", Method=Method,
results=RHS, Error=Sr, TrueErr=TrueErr, r=r)
elif not ydata or not xdata:
error = 'Missing Points'
return render_template('LeastSquareReg.html', url="gr-a8q7EDbY", title='Least Square Reg.',
css="LeastSquareReg.css", wing="CF Header.png", logo="Logo.svg", Method=Method,
results='Missing Points', Error='...', TrueErr='...', r='...', error = error)
elif xdata and ydata:
error = 'Singular/Out of Domain Matrix'
return render_template('LeastSquareReg.html', url="gr-a8q7EDbY", title='Least Square Reg.',
css="LeastSquareReg.css", wing="CF Header.png", logo="Logo.svg", Method=Method,
results='Singular/Out of Domain Matrix', Error='...', TrueErr='...', r='...', error=error)
elif Method == 'Best-Fitting-Family-of-Curves':
i = 0
xdata = []
ydata = []
while (request.form['x_coordinates' + str(i)]!='' and request.form['y_coordinates' + str(i)]!=''):
try:
xdata.append(float(request.form['x_coordinates' + str(i)]))
ydata.append(float(request.form['y_coordinates' + str(i)]))
except:
pass
i += 1
try:
result, Family, Error, STnd = Curve_Family_Detective(xdata, ydata, 12)
TrueErr = TrueError(ydata, 12)
r = round((abs(Error-TrueErr)/TrueErr)**0.5,12)
except:
error = "Missing Points"
result = "Missing Points"
Error = '...'
TrueErr = '...'
r = '...'
return render_template('LeastSquareReg.html', url="gr-a8q7EDbY", title='Least Square Reg.',
css="LeastSquareReg.css", wing="CF Header.png", logo="Logo.svg", Method=Method,
results=result, Error=Error, TrueErr=TrueErr, r=r, error = error)
if result !="" and Error !="" :
return render_template('LeastSquareReg.html', url="gr-a8q7EDbY", title='Least Square Reg.',
css="LeastSquareReg.css", wing="CF Header.png", logo="Logo.svg", Method=Method,
results=result, Error=Error, TrueErr=TrueErr, r=r, family=Family + ' curves')
elif not xdata or not ydata:
error = 'Missing Points'
return render_template('LeastSquareReg.html', url="gr-a8q7EDbY", title='Least Square Reg.',
css="LeastSquareReg.css", wing="CF Header.png", logo="Logo.svg", Method=Method,
results='Missing Points', Error='...', TrueErr='...', r='...', family= ' ...',error = error)
elif xdata and ydata:
return render_template('LeastSquareReg.html', url="gr-a8q7EDbY", title='Least Square Reg.',
css="LeastSquareReg.css", wing="CF Header.png", logo="Logo.svg", Method=Method,
results='Singular Matrix/ Out of Domain Matrix', Error='...', TrueErr='...',
r='...', family= ' ...', error = error)
else:
error = 'Chose a Method'
return render_template('LeastSquareReg.html', url="gr-a8q7EDbY", title='Least Square Reg.',
css="LeastSquareReg.css", wing="CF Header.png", logo="Logo.svg",
Method=Method, error = error)
else:
error = 'Singular/Out of Domain Matrix'
return render_template('LeastSquareReg.html', url="gr-a8q7EDbY", title='Least Square Reg.',
css="LeastSquareReg.css", wing="CF Header.png", logo="Logo.svg")
@app.route("/SurfaceFitting", methods=['GET', 'POST'])
def SurfaceFitting():
if request.method == 'POST':
Sr = 0
LHS = 0
i = 0
xdata = []
ydata = []
zdata = []
RHS = 0
while (request.form['x_coordinates' + str(i)]!='' and request.form['y_coordinates' + str(i)]!='' and request.form['z_coordinates' + str(i)]!=''):
try:
xdata.append(float(request.form['x_coordinates' + str(i)]))
ydata.append(float(request.form['y_coordinates' + str(i)]))
zdata.append(float(request.form['z_coordinates' + str(i)]))
except:
pass
i += 1
j = 0
Fdata = [request.form['Abdullah_Knows_It_All']]
while request.form['term' + str(j)]:
Fdata.append(request.form['term' + str(j)])
j += 1
if xdata and Fdata:
try:
LHS, RHS, Constants, Sr = Surface_Fit_Beta(xdata, ydata, zdata, Fdata, 10)
except:
return render_template('SurfaceFitting.html', url="mRjVy0MSUI0",
title='Surface Fitting', css="SurfaceFitting.css", wing="CF Header.png",
logo="Logo.svg", error = 'Invalid Input', results='Invalid Input', Error='...')
if RHS:
GriX, GriY, GriZ = PointsFor3DSF(xdata,ydata,RHS)
GriZ = GriZ.transpose()
x1 = list(GriX)
y1 = list(GriY)
z1 = []
for i in range(np.shape(GriZ)[0]):
z1.append(list(GriZ[i]))
if LHS and RHS and not Sr == '':
return render_template('SurfaceFitting.html', url="mRjVy0MSUI0",
title='Surface Fitting', css="SurfaceFitting.css", wing="CF Header.png",
logo="Logo.svg", results=RHS, Error=Sr, x1 = x1, y1 = y1, z1 = z1)
elif not xdata:
return render_template('SurfaceFitting.html', url="mRjVy0MSUI0",
title='Surface Fitting', css="SurfaceFitting.css", wing="CF Header.png",
logo="Logo.svg", error = 'Missing Points', results='Missing Points', Error='...')
else:
return render_template('SurfaceFitting.html', url="mRjVy0MSUI0",
title='Surface Fitting', css="SurfaceFitting.css", wing="CF Header.png",
logo="Logo.svg", results='Singular Matrix/Out of Domain', Error='...', error = 'Singular Matrix/Out of Domain')
else:
return render_template('SurfaceFitting.html', url="mRjVy0MSUI0", title='Surface Fitting',
css="SurfaceFitting.css", wing="CF Header.png", logo="Logo.svg")
@app.route("/Differentiation", methods=['GET', 'POST'])
def Differentiation():
if request.method == 'POST':
results=''
error=''
try:
Method = ''
Method = request.form['Method']
Calculation_Point = 0
Calculation_Point = float(request.form['Calculation Point'])
except:
error="Invalid Calculation Point"
if Method == 'Table' :
x = []
y = []
i = 0
while (request.form['x' + str(i)]!='' and request.form['y' + str(i)]!=''):
try:
x.append(float(request.form['x' + str(i)]))
y.append(float(request.form['y' + str(i)]))
i += 1
except:
pass
try:
results = TableDeriv(Calculation_Point, x, y)
except:
error="Invalid Input"
else:
try:
Function = ''
Function = request.form['Function']
results = []
h = 0
order = 0
h = float(request.form['step'])
order = float(request.form['order'])
results = FuncDeriv(Function, h, order, Calculation_Point)
import sympy
from sympy import symbols
x = symbols('x');
F=sympy.sympify(Function )
y=sympy.lambdify([x],F)
Tango=str(results[0])+"*x"+"+"+str(y(Calculation_Point)-results[0]*Calculation_Point)
except:
error="Invalid Input"
return render_template('Differentiation.html', url='KPnkAIZqWFQ', title='Differentiation', css="Differentiation.css", wing="SE - Copy.png", logo="Logo Crimson.svg" ,error=error, results = results , Method = Method,Tango=Tango)
#return render_template('Differentiation.html', url='KPnkAIZqWFQ', title='Differentiation', css="Differentiation.css", wing="SE - Copy.png", logo="Logo Crimson.svg" )
else:
return render_template('Differentiation.html', url='KPnkAIZqWFQ', title='Differentiation', css="Differentiation.css", wing="SE - Copy.png", logo="Logo Crimson.svg" )
@app.route("/Integration", methods=['GET', 'POST'])
def Integration():
if request.method == 'POST':
Dim=''
function=''
x1=''
x2=''
y1=''
y2=''
N2=''
N=''
Result=''
ResultTrap=''
error=''
_error=''
TrapError=''
exact=''
ResultMin=''
ErrorMin=''
ResultRom=''
OrderOfError=''
if 'Dim' in request.form:
NumOfVar=request.form['Dim']
if NumOfVar == '1':
function=request.form['func']
function=function.replace("^","**")
function=function.replace("PI","pi")
try:
x1=float(request.form['x1'])
x2=float(request.form['x2'])
except:
if _error=='':
_error="Invalid x1 , or x2"
try:
N=int(request.form['n1'])
except:
if _error=='':
_error="Invalid N"
try:
OrderOfError=int(request.form['OrderOfError'])
except:
ResultRom="Order of Error is invalid"
try:
if function != '' and x1 != '' and x2 != '' and N != '' and N > 6:
Result,error=myfun(function,x1,x2,1,1,6)
except:
pass
else:
try:
Result,error=myfun(function,x1,x2,1,1,N)
except:
if _error=='':
_error="Invalid Inputs"
try:
if function != '' and x1 != '' and x2 != '':
exact=Exact(function,x1,x2,1,1,1,1,1)
if OrderOfError != '':
if OrderOfError%2==0:
ResultRom=RombergRule(function, int(NumOfVar),x1,x2,1,1,1,1,OrderOfError)
else:
ResultRom="Order of Error must be even"
if function != '' and x1 != '' and x2 != '' and N != '':
ResultTrap=Trapezoidal_Integ(function,x1,x2,N)
ResultMin,ErrorMin=single_mixe_rule(function,x1,x2,N)
TrapError=Trapezoidal_error(function,x1,x2,N)
except:
if _error=='':
_error="Invalid Inputs"
return render_template('Integration.html', url="EgQa0aKmUyk" , title='Integration', css="Integration.css", wing="SE - Copy.png", logo="Logo Crimson.svg",Dim = NumOfVar,function=function,x1=x1,x2=x2,n1=N,Result=Result,exact=exact,_error=_error,error=error,ResultTrap=ResultTrap,TrapError=TrapError,ResultMin=ResultMin,ErrorMin=ErrorMin,ResultRom=ResultRom,OrderOfError=OrderOfError)
elif NumOfVar == '2':
try:
function=request.form['func']
except:
if _error=='':
_error="Invalid Function"
try:
x1=float(request.form['x1'])
except:
if _error=='':
_error="Invalid x1"
try:
x2=float(request.form['x2'])
except:
if _error=='':
_error="Invalid x2"
try:
N=int(request.form['n1'])
except:
if _error=='':
_error="Invalid N"
try:
y1=float(request.form['y1'])
except:
if _error=='':
_error="Invalid y1"
try:
y2=float(request.form['y2'])
except:
if _error=='':
_error="Invalid y2"
try:
N2=int(request.form['n2'])
except:
if _error=='':
_error="Invalid N2"
try:
OrderOfError=int(request.form['OrderOfError'])
except:
ResultRom="Order of Error is invalid"
try:
if N > 6:
Result,error=myfun(function,x1,x2,y1,y2,6)
except:
pass
else:
try:
Result,error=myfun(function,x1,x2,y1,y2,N)
except:
if _error=='':
_error="Invalid Input"
try:
if function != '' and x1 != '' and x2 != '':
exact=Exact(function,x1,x2,y1,y2,1,1,2)
if OrderOfError != '':
if OrderOfError%2==0:
ResultRom=RombergRule(function, int(NumOfVar),x1,x2,y1,y2,1,1,OrderOfError)
else:
ResultRom="Order of Error must be even"
if function != '' and x1 != '' and x2 != '' and N != '':
ResultMin=double_mixed_rule (function,x1,x2,N,y1,y2,N2)
ResultTrap=Trapezoidal_Double_Integ(function,x1,x2,N,y1,y2,N2)
except:
if _error=='':
_error="Invalid Input"
return render_template('Integration.html', url="EgQa0aKmUyk" , title='Integration', css="Integration.css", wing="SE - Copy.png", logo="Logo Crimson.svg",Dim = NumOfVar,function=function,x1=x1,x2=x2,y1=y1,y2=y2,n2=N2,n1=N,Result=Result,exact=exact,error=error,ResultTrap=ResultTrap,ResultMin=ResultMin,ResultRom=ResultRom,OrderOfError=OrderOfError,_error=_error)
else:
z1=''
z2=''
N3=''
try:
function=request.form['func']
except:
if _error=='':
_error="Invalid function"
try:
x1=float(request.form['x1'])
except:
if _error=='':
_error="Invalid x1"
try:
x2=float(request.form['x2'])
except:
if _error=='':
_error="Invalid x2"
try:
N=int(request.form['n1'])
except:
if _error=='':
_error="Invalid N1"
try:
y1=float(request.form['y1'])
except:
if _error=='':
_error="Invalid y1"
try:
y2=float(request.form['y2'])
except:
if _error=='':
_error="Invalid y2"
try:
N2=int(request.form['n2'])
except:
if _error=='':
_error="Invalid N2"
try:
z1=float(request.form['z1'])
except:
if _error=='':
_error="Invalid z1"
try:
z2=float(request.form['z2'])
except:
if _error=='':
_error="Invalid z2"
try:
N3=int(request.form['n3'])
except:
if _error=='':
_error="Invalid N3"
try:
OrderOfError=int(request.form['OrderOfError'])
except:
ResultRom="Order of Error is invalid"
Result="too complex"
try:
if function != '' and x1 != '' and x2 != '':
exact=Exact(function,x1,x2,y1,y2,z1,z2,3)
if OrderOfError != '':
if OrderOfError%2==0:
ResultRom=RombergRule(function, int(NumOfVar),x1,x2,y1,y2,z1,z2,OrderOfError)
else:
ResultRom="Order of Error must be even"
if function != '' and x1 != '' and x2 != '' and N != '':
ResultTrap=Trapezoidal_Triple_Integ(function,x1,x2,N,y1,y2,N2,z1,z2,N3)
ResultMin=triple_mixed_rule (function,x1,x2,N,y1,y2,N2,z1,z2,N3)
except:
if _error=='':
_error="Invalid Inputs"
return render_template('Integration.html', url="EgQa0aKmUyk" , title='Integration', css="Integration.css", wing="SE - Copy.png", logo="Logo Crimson.svg",_error=_error,Dim = NumOfVar,function=function,x1=x1,x2=x2,n1=N,Result=Result,exact=exact,ResultTrap=ResultTrap,y1=y1,y2=y2,n2=N2,z1=z1,z2=z2,n3=N3,ResultMin=ResultMin,ResultRom=ResultRom,OrderOfError=OrderOfError)
else:
_error="Choose a Method"
return render_template('Integration.html', url="EgQa0aKmUyk" , title='Integration', css="Integration.css", wing="SE - Copy.png", logo="Logo Crimson.svg",_error=_error)
else:
return render_template('Integration.html' , url="EgQa0aKmUyk" , title='Integration', css="Integration.css", wing="SE - Copy.png", logo="Logo Crimson.svg")
@app.route("/ODERK", methods=['GET', 'POST'])
def ODERK():
if request.method == 'POST':
error = ''
x0 = ''
fx0 = ''
h = ''
xn = ''
result = ''
equation = request.form['equation']
if not(equation):
return render_template('ODERK.html', url="gC-XbgLj63I", title='ODE Runge-Kutta',
css="ODERK.css", wing="DE - Copy.png", logo="Logo.svg",
error = 'Enter Equation')
try:
x0 = float(request.form['x0'])
except:
return render_template('ODERK.html', url="gC-XbgLj63I", title='ODE Runge-Kutta',
css="ODERK.css", wing="DE - Copy.png", logo="Logo.svg",
error = 'Enter X0')
try:
fx0 = float(request.form['fx0'])
except:
return render_template('ODERK.html', url="gC-XbgLj63I", title='ODE Runge-Kutta',
css="ODERK.css", wing="DE - Copy.png", logo="Logo.svg",
error = 'Enter fX0')
try:
h = float(request.form['h'])
except:
return render_template('ODERK.html', url="gC-XbgLj63I", title='ODE Runge-Kutta',
css="ODERK.css", wing="DE - Copy.png", logo="Logo.svg",
error = 'Enter h')
try:
xn = float(request.form['xn'])
except:
return render_template('ODERK.html', url="gC-XbgLj63I", title='ODE Runge-Kutta',
css="ODERK.css", wing="DE - Copy.png", logo="Logo.svg",
error = 'Enter Xn')
try:
result = rungeKutta(x0, fx0, xn, h, equation)
except:
error = 'Can not Solve at This Point'
TrueResult = TrueDifferentials(equation,x0,fx0,xn)
Truerror=TrueErrorr(TrueResult,result[-1])
return render_template('ODERK.html', url="gC-XbgLj63I", title='ODE Runge-Kutta',
css="ODERK.css", wing="DE - Copy.png", logo="Logo.svg",
results=result, length=len(result), Truerror=Truerror, error = error)
else:
return render_template('ODERK.html', url="gC-XbgLj63I", title='ODE Runge-Kutta',
css="ODERK.css", wing="DE - Copy.png", logo="Logo.svg")
@app.route("/ODEEH", methods=['GET', 'POST'])
def ODEEH():
#*********
Method =0
O_Dim = 0
Eqs_No = 0
temp_to_test=0
h_or_n=''
iter_or_stoppingC=''
StoppingCriteria = 0.0
num_iteration=0
List_initial_values=['']*7 # [0]->x0 ,[1]-> y0 ,[2]->z0 ,[3]->t0 ,[4]->y'0 ,[5]->y"0 ,[6]->x_at
List_eqs = ['']*5 #[0]-> y',[1]->y",[2]->y"',[3]->z',[4]->t'
y_exact=''
Length = 0
result = []
#*****************************
if request.method == 'POST':
if 'Method' in request.form:
temp_to_test = request.form['Method']
if temp_to_test=='Euler':
Method=1
if temp_to_test=='Heun':
Method=2
if 'ODim' in request.form:
O_Dim = int(request.form['ODim'])
if 'Dim' in request.form:
Eqs_No = int(request.form['Dim'])
if not request.form['Stopping Criteria']=='':
try:
checker = float(request.form['Stopping Criteria'])
except ValueError :
if Method==2:
return render_template('ODEEH.html', url="pntenkMEUyk", title='ODE Euler&Huen', css="ODEEH.css",
wing="DE - Copy.png",
logo="Logo.svg", error="Ops!.. Enter valid data for Stopping Criteria ")
else:
return render_template('ODEEH.html', url="pntenkMEUyk", title='ODE Euler&Huen', css="ODEEH.css",
wing="DE - Copy.png",
logo="Logo.svg", error="Ops!.. Enter valid data for Step Size(h) ")
else:
temp_to_test = request.form['Stopping Criteria']
if Method == 2:
StoppingCriteria = float(temp_to_test)
num_iteration=''
iter_or_stoppingC ='s'
else:
StoppingCriteria = float(temp_to_test)
num_iteration = ''
h_or_n = 'h'
elif not request.form['Number of iterations']=='':
try:
checker = float(request.form['Number of iterations'])
except ValueError :
if Method==2:
return render_template('ODEEH.html', url="pntenkMEUyk", title='ODE Euler&Huen', css="ODEEH.css",
wing="DE - Copy.png",
logo="Logo.svg", error="Ops!..Enter valid data for Number of iterations ")
else:
return render_template('ODEEH.html', url="pntenkMEUyk", title='ODE Euler&Huen',
css="ODEEH.css",
wing="DE - Copy.png",
logo="Logo.svg",
error="Ops!..Enter valid data for Number of Steps (n)")
else:
temp_to_test = request.form['Number of iterations']
if Method == 2:
num_iteration=int(temp_to_test)
StoppingCriteria=''
iter_or_stoppingC = 'n'
else:
num_iteration = int(temp_to_test)
StoppingCriteria = ''
h_or_n = 'n'
else:
StoppingCriteria = ''
num_iteration = ''
if Method==2:
return render_template('ODEEH.html', url="pntenkMEUyk", title='ODE Euler&Huen', css="ODEEH.css",
wing="DE - Copy.png",
logo="Logo.svg", error="You forgot entering data for Stoping Criteria OR Number of iterations -- only one of them is needed--")
else:
return render_template('ODEEH.html', url="pntenkMEUyk", title='ODE Euler&Huen', css="ODEEH.css",
wing="DE - Copy.png",
logo="Logo.svg",
error="You forgot entering data for Step Size(h) OR Number of Steps(n) -- only one of them is needed--")
#******************************
if not request.form['Atx'] =='':
try:
checker = float(request.form['Atx'])
except ValueError:
return render_template('ODEEH.html', url="pntenkMEUyk", title='ODE Euler&Huen', css="ODEEH.css",
wing="DE - Copy.png",
logo="Logo.svg", error="Ops!.. Enter valid data for x to evaluate at:")
else:
temp_to_test = float(request.form['Atx'])
if not temp_to_test == '':
List_initial_values[6] = temp_to_test # x to evaluate at =
else:
return render_template('ODEEH.html', url="pntenkMEUyk", title='ODE Euler&Huen', css="ODEEH.css", wing="DE - Copy.png", logo="Logo.svg",error="Ops!..You forgot entering X to evaluate at :")
if Method==2 :
temp_to_test = (request.form['yex'])
if not temp_to_test == '':
try:
func_xyzt(request.form['yex'],1,1,1,1)
except NameError:
return render_template('ODEEH.html', url="pntenkMEUyk", title='ODE Euler&Huen', css="ODEEH.css",
wing="DE - Copy.png",
logo="Logo.svg", error="Ops!.. Enter valid equation for Y exact (x) ")
else:
y_exact = temp_to_test # func to calc exact value of y:
#***********
if not request.form['x'] == '':
try:
checker = float(request.form['x'])
except ValueError:
return render_template('ODEEH.html', url="pntenkMEUyk", title='ODE Euler&Huen', css="ODEEH.css",
wing="DE - Copy.png",
logo="Logo.svg", error="Ops!.. Enter valid data for Xo ")
else:
temp_to_test = float(request.form['x'])
List_initial_values[0] = float(temp_to_test)
else:
return render_template('ODEEH.html', url="pntenkMEUyk", title='ODE Euler&Huen', css="ODEEH.css", wing="DE - Copy.png", logo="Logo.svg",error="Ops!..You forgot entering Xo value:")
if (Method==1 and (Eqs_No==1 or Eqs_No==2 or Eqs_No==3 )) or (Method==2 and O_Dim==1 and (Eqs_No==1 or Eqs_No==2)) or (Method==2 and (O_Dim==2 or O_Dim==3)):
temp_to_test = (request.form['y'])
if not temp_to_test == '':
try:
checker = float(request.form['y'])
except ValueError:
return render_template('ODEEH.html', url="pntenkMEUyk", title='ODE Euler&Huen', css="ODEEH.css",
wing="DE - Copy.png",
logo="Logo.svg", error="Ops!.. Enter valid data for Yo")
else:
List_initial_values[1] = float(temp_to_test)
else:
return render_template('ODEEH.html', url="pntenkMEUyk", title='ODE Euler&Huen', css="ODEEH.css", wing="DE - Copy.png", logo="Logo.svg",error="Ops!..You forgot entering Yo value:")
if (Method==1 and (Eqs_No==2 or Eqs_No==3))or (Method==2 and O_Dim==1 and Eqs_No==2):
temp_to_test = (request.form['z'])
if not temp_to_test == '':
try:
checker = float(request.form['z'])
except ValueError:
return render_template('ODEEH.html', url="pntenkMEUyk", title='ODE Euler&Huen', css="ODEEH.css",
wing="DE - Copy.png",
logo="Logo.svg", error="Ops!.. Enter valid data for Zo")
else:
List_initial_values[2] = float(temp_to_test)
else:
return render_template('ODEEH.html', url="pntenkMEUyk", title='ODE Euler&Huen', css="ODEEH.css", wing="DE - Copy.png", logo="Logo.svg",error="Ops!..You forgot entering Zo value:")
if (Method==1 and Eqs_No==3):
temp_to_test = (request.form['t'])
if not temp_to_test == '':
try:
checker = float(request.form['t'])
except ValueError:
return render_template('ODEEH.html', url="pntenkMEUyk", title='ODE Euler&Huen', css="ODEEH.css",
wing="DE - Copy.png",
logo="Logo.svg", error="Ops!.. Enter valid data for to")
else:
List_initial_values[3] = float(temp_to_test)
else:
return render_template('ODEEH.html', url="pntenkMEUyk", title='ODE Euler&Huen', css="ODEEH.css", wing="DE - Copy.png", logo="Logo.svg",error="Ops!..You forgot entering to value:")
if (Method==2 and (O_Dim==3 or O_Dim==2)):
temp_to_test = (request.form['ydash'])
if not temp_to_test == '':
try:
checker = float(request.form['ydash'])
except ValueError:
return render_template('ODEEH.html', url="pntenkMEUyk", title='ODE Euler&Huen', css="ODEEH.css",
wing="DE - Copy.png",
logo="Logo.svg", error="Ops!.. Enter valid data for Y’o ")
else:
List_initial_values[4] = float(temp_to_test)
else:
return render_template('ODEEH.html', url="pntenkMEUyk", title='ODE Euler&Huen', css="ODEEH.css", wing="DE - Copy.png", logo="Logo.svg",error="Ops!..You forgot entering Y’o value:")
if (Method==2 and O_Dim==3):
temp_to_test = (request.form['yddash'])
if not temp_to_test == '':
try:
checker = float(request.form['yddash'])
except ValueError:
return render_template('ODEEH.html', url="pntenkMEUyk", title='ODE Euler&Huen', css="ODEEH.css",
wing="DE - Copy.png",
logo="Logo.svg", error="Ops!.. Enter valid data for Y’’o ")
else:
List_initial_values[5] = float(temp_to_test)
else:
return render_template('ODEEH.html', url="pntenkMEUyk", title='ODE Euler&Huen', css="ODEEH.css", wing="DE - Copy.png", logo="Logo.svg",error="Ops!..You forgot entering Y’’o value:")
#*********************************************
if (Method == 1 and (Eqs_No == 2 or Eqs_No==1 or Eqs_No==3)) or (Method ==2 and O_Dim==1 and(Eqs_No == 1 or Eqs_No==2 )):
if not request.form['Y1']== '':
try:
func_xyzt(str(request.form['Y1']),1,1,1,1)
except NameError:
return render_template('ODEEH.html', url="pntenkMEUyk", title='ODE Euler&Huen', css="ODEEH.css",
wing="DE - Copy.png",
logo="Logo.svg", error="Ops!.. Enter valid equation for Y’( )")
else:
List_eqs[0] = str(request.form['Y1'])
else:
return render_template('ODEEH.html', url="pntenkMEUyk", title='ODE Euler&Huen', css="ODEEH.css", wing="DE - Copy.png",
logo="Logo.svg", error="Ops!..You forgot entering Y’( ):")
if (Method == 2 and (O_Dim == 2 )):
temp_to_test = (request.form['Y2'])
if not temp_to_test == '':
try:
func_xyzt(str(request.form['Y2']), 1, 1, 1, 1)
except NameError:
return render_template('ODEEH.html', url="pntenkMEUyk", title='ODE Euler&Huen', css="ODEEH.css",
wing="DE - Copy.png",
logo="Logo.svg", error="Ops!..Enter valid equation for Y’’( )")
else:
List_eqs[1] = request.form['Y2']
else:
return render_template('ODEEH.html', url="pntenkMEUyk", title='ODE Euler&Huen', css="ODEEH.css", wing="DE - Copy.png",
logo="Logo.svg", error="Ops!..You forgot entering Y’’( ):")
if (Method == 2 and ( O_Dim == 3)):
temp_to_test = (request.form['Y3'])
if not temp_to_test == '':
try:
func_xyzt(str(request.form['Y3']), 1, 1, 1, 1)
except NameError:
return render_template('ODEEH.html', url="pntenkMEUyk", title='ODE Euler&Huen', css="ODEEH.css",
wing="DE - Copy.png",
logo="Logo.svg", error="Ops!..Enter valid equation for Y’’’( )")
else:
List_eqs[2] = request.form['Y3']
else:
return render_template('ODEEH.html', url="pntenkMEUyk", title='ODE Euler&Huen', css="ODEEH.css", wing="DE - Copy.png",
logo="Logo.svg", error="Ops!..You forgot entering Y’’’( )")
if (Method == 2 and (O_Dim ==1) and Eqs_No==2) or (Method == 1 and ( Eqs_No==2 or Eqs_No==3)):
temp_to_test = ( request.form['Z1'])
if not temp_to_test == '':
try:
func_xyzt(str(request.form['Z1']), 1, 1, 1, 1)
except NameError: