quarticequation 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ """
2
+ Initialization of the functions and modules quartic equation
3
+ """
4
+
5
+ from .quarticequation import *
6
+ from .version import __version__,__author__,__copyright__,__credits__,__license__,__maintainer__,__email__,__status__
@@ -0,0 +1,10 @@
1
+ # pylint: disable=invalid-name
2
+ """
3
+ Command line handling
4
+ """
5
+
6
+ import sys
7
+
8
+ if __name__ == '__main__':
9
+ from quarticequation import quarticcmd
10
+ quarticcmd.CommandLine( sys.argv )
@@ -0,0 +1,189 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+ """
5
+ Command line interface
6
+
7
+ Copyright (C) 2024 Gien van den Enden - swvandenenden@gmail.com
8
+
9
+ This program is free software: you can redistribute it and/or modify
10
+ it under the terms of the GNU General Public License as published by
11
+ the Free Software Foundation, either version 3 of the License, or
12
+ (at your option) any later version.
13
+
14
+ This program is distributed in the hope that it will be useful,
15
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ GNU General Public License for more details.
18
+
19
+ You should have received a copy of the GNU General Public License
20
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
21
+
22
+ """
23
+
24
+ import symexpress3
25
+ import quarticequation
26
+
27
+
28
+ def CalcSolutions( quarticVars, outputFormat ):
29
+ """
30
+ Calculate the quartic solutions
31
+ """
32
+ if len( quarticVars ) == 0:
33
+ print( "No parameters are given, nothing to calculate" )
34
+ return
35
+
36
+ if len( quarticVars ) > 5:
37
+ print( f"Only the first 5 parameters are used, found {len( quarticVars )} parameters" )
38
+
39
+ # default output format, solutions as string and calculated values
40
+ if outputFormat in( "", None ):
41
+ outputFormat = "sc"
42
+
43
+ try:
44
+
45
+ clsQuartic = quarticequation.QuarticEquation()
46
+ output = None
47
+
48
+ # set variables
49
+ for iCount, varData in enumerate( quarticVars ):
50
+ # print( f"iCount: {iCount}, data: {varData}" )
51
+ # pylint: disable=multiple-statements
52
+ if iCount == 0: clsQuartic.a = symexpress3.ConvertToSymexpress3String( varData )
53
+ elif iCount == 1: clsQuartic.b = symexpress3.ConvertToSymexpress3String( varData )
54
+ elif iCount == 2: clsQuartic.c = symexpress3.ConvertToSymexpress3String( varData )
55
+ elif iCount == 3: clsQuartic.d = symexpress3.ConvertToSymexpress3String( varData )
56
+ elif iCount == 4: clsQuartic.e = symexpress3.ConvertToSymexpress3String( varData )
57
+ else:
58
+ break
59
+
60
+ # must set real calculation before starting
61
+ if 'c' in outputFormat:
62
+ clsQuartic.realCalc = True
63
+ else:
64
+ clsQuartic.realCalc = False
65
+
66
+ if 'h' in outputFormat:
67
+ output = symexpress3.SymToHtml( None, "Quartic equation" )
68
+ clsQuartic.htmlOutput = output
69
+
70
+ # calculate the solutions
71
+ clsQuartic.calcSolutions()
72
+
73
+ # output data
74
+ for cOutput in outputFormat:
75
+ if cOutput == "s":
76
+ print( f"x1: {clsQuartic.x1Optimized}" )
77
+ print( f"x2: {clsQuartic.x2Optimized}" )
78
+ print( f"x3: {clsQuartic.x3Optimized}" )
79
+ print( f"x4: {clsQuartic.x4Optimized}" )
80
+
81
+ elif cOutput == "n":
82
+ print( f"x1 not optimized: {clsQuartic.x1}" )
83
+ print( f"x2 not optimized: {clsQuartic.x2}" )
84
+ print( f"x3 not optimized: {clsQuartic.x3}" )
85
+ print( f"x4 not optimized: {clsQuartic.x4}" )
86
+
87
+ elif cOutput == "c":
88
+ print( f"x1 value: {clsQuartic.x1Value}" )
89
+ print( f"x2 value: {clsQuartic.x2Value}" )
90
+ print( f"x3 value: {clsQuartic.x3Value}" )
91
+ print( f"x4 value: {clsQuartic.x4Value}" )
92
+
93
+ elif cOutput == "h":
94
+ pass # do nothing html (output) is already set
95
+
96
+ else:
97
+ print( f"Unknown output format '{cOutput}' ignored" )
98
+
99
+ if output != None:
100
+ output.closeFile()
101
+ output = None
102
+
103
+ except Exception as exceptAll: # pylint: disable=broad-exception-caught
104
+ print( f"Error: {str( exceptAll )}" )
105
+
106
+
107
+
108
+ def DisplayVersion():
109
+ """
110
+ Display version information
111
+ """
112
+ print( "Version : " + quarticequation.__version__ )
113
+
114
+ print( "Author : " + quarticequation.__author__ )
115
+ print( "Copyright : " + quarticequation.__copyright__ )
116
+ print( "License : " + quarticequation.__license__ )
117
+ print( "Maintainer : " + quarticequation.__maintainer__ )
118
+ print( "Email : " + quarticequation.__email__ )
119
+ print( "Status : " + quarticequation.__status__ )
120
+
121
+
122
+ def DisplayHelp():
123
+ """
124
+ Display help
125
+ """
126
+ print( "Give the exact solutions of a quartic equation: a x^4 + b x^3 + c x^2 + d x + e = 0" )
127
+ print( " " )
128
+ print( "usage: python -m quarticequation [options] [arg]" )
129
+ print( "options: " )
130
+ print( " -h : Help" )
131
+ print( " -v : Version information" )
132
+ print( " -o <format> : Output format" )
133
+ print( " s - string format (default)" )
134
+ print( " n - not optimized solutions in string format" )
135
+ print( " c - calculated values (default)" )
136
+ print( " h - html" )
137
+ print( "arg:" )
138
+ print( "a b c d" )
139
+ print( "The arguments can be a symexpress3 string or a real number" )
140
+ print( " " )
141
+ print( "Example: " )
142
+ print( 'python -m quarticequation -o nsc 1 2 3 4 5' )
143
+
144
+ def CommandLine( argv ):
145
+ """
146
+ Process the quartic equation command line parameters
147
+ """
148
+ outputFormat = ""
149
+ quarticvars = []
150
+
151
+ nrarg = len( argv )
152
+
153
+ # nothing given, then display help
154
+ if nrarg <= 1:
155
+ DisplayHelp()
156
+
157
+ mode = ""
158
+ for iCnt in range( 1, nrarg ) :
159
+ cArg = argv[ iCnt ]
160
+
161
+ if mode == "output":
162
+ outputFormat = cArg
163
+ mode = ""
164
+ continue
165
+
166
+ if cArg == "-h" :
167
+ DisplayHelp()
168
+ return # direct stop by help
169
+
170
+ if cArg == "-v" :
171
+ DisplayVersion()
172
+ return # direct stop by version information
173
+
174
+ if cArg == "-o":
175
+ mode = "output"
176
+
177
+ else:
178
+ if cArg.startswith( "-" ):
179
+ print( f"Unknown option: {cArg}, use -h for help")
180
+ else:
181
+ # collect arguments
182
+ quarticvars.append( cArg )
183
+
184
+ CalcSolutions( quarticvars, outputFormat )
185
+
186
+
187
+ # ---------------------------
188
+ # The end
189
+ # ---------------------------