parent
5dc23d5184
commit
2b94f5ce4f
@ -1,8 +0,0 @@
|
|||||||
# Default ignored files
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
||||||
# Editor-based HTTP Client requests
|
|
||||||
/httpRequests/
|
|
||||||
# Datasource local storage ignored files
|
|
||||||
/dataSources/
|
|
||||||
/dataSources.local.xml
|
|
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="jdk" jdkName="C:\ProgramData\anaconda3" jdkType="Python SDK" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
@ -0,0 +1,25 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="DuplicatedCode" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||||
|
<Languages>
|
||||||
|
<language minSize="54" name="Python" />
|
||||||
|
</Languages>
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||||
|
<option name="ignoredErrors">
|
||||||
|
<list>
|
||||||
|
<option value="N806" />
|
||||||
|
<option value="N802" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
|
<option name="ignoredIdentifiers">
|
||||||
|
<list>
|
||||||
|
<option value="list.__getitem__" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</inspection_tool>
|
||||||
|
</profile>
|
||||||
|
</component>
|
@ -1,25 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="JupyterPersistentConnectionParameters">
|
|
||||||
<option name="moduleParameters">
|
|
||||||
<map>
|
|
||||||
<entry key="$USER_HOME$/AppData/Local/Temp/01U_Interpolation_A.ipynb/.idea/01U_Interpolation_A.ipynb.iml">
|
|
||||||
<value>
|
|
||||||
<JupyterConnectionParameters>
|
|
||||||
<option name="managed" value="true" />
|
|
||||||
<option name="port" value="8008" />
|
|
||||||
</JupyterConnectionParameters>
|
|
||||||
</value>
|
|
||||||
</entry>
|
|
||||||
<entry key="$USER_HOME$/Nextcloud/_Container/Hausaufgaben/Uebung_Numerik_Prog/.idea/Uebung_Numerik_Prog.iml">
|
|
||||||
<value>
|
|
||||||
<JupyterConnectionParameters>
|
|
||||||
<option name="managed" value="true" />
|
|
||||||
<option name="sdkHomePath" value="C:\Users\janni\AppData\Local\Microsoft\WindowsApps\python3.10.exe" />
|
|
||||||
</JupyterConnectionParameters>
|
|
||||||
</value>
|
|
||||||
</entry>
|
|
||||||
</map>
|
|
||||||
</option>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
@ -1,8 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<<<<<<< Updated upstream
|
<component name="ProjectRootManager" version="2" project-jdk-name="C:\ProgramData\anaconda3" project-jdk-type="Python SDK" />
|
||||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10.6 WSL (Ubuntu): (/home/janniclas/.virtualenvs/Informationssysteme/bin/python)" project-jdk-type="Python SDK" />
|
|
||||||
=======
|
|
||||||
<component name="ProjectRootManager" version="2" project-jdk-name="C:\ProgramData\anaconda3 (2)" project-jdk-type="Python SDK" />
|
|
||||||
>>>>>>> Stashed changes
|
|
||||||
</project>
|
</project>
|
@ -1,15 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module type="PYTHON_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager">
|
|
||||||
<content url="file://$MODULE_DIR$">
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/Virtualenv" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
|
||||||
</content>
|
|
||||||
<<<<<<< Updated upstream
|
|
||||||
<orderEntry type="jdk" jdkName="Python 3.10.6 WSL (Ubuntu): (/home/janniclas/.virtualenvs/Informationssysteme/bin/python)" jdkType="Python SDK" />
|
|
||||||
=======
|
|
||||||
<orderEntry type="jdk" jdkName="C:\ProgramData\anaconda3 (2)" jdkType="Python SDK" />
|
|
||||||
>>>>>>> Stashed changes
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
@ -1,9 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="RGraphicsSettings">
|
|
||||||
<option name="height" value="576" />
|
|
||||||
<option name="resolution" value="75" />
|
|
||||||
<option name="version" value="2" />
|
|
||||||
<option name="width" value="2048" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="RSettings">
|
|
||||||
<option name="interpreterPath" value="C:\Program Files\R\R-4.3.2\bin\R.exe" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
@ -0,0 +1,94 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ChangeListManager">
|
||||||
|
<list default="true" id="c8162e9c-0010-43df-bfbc-c294a3a64a5d" name="Changes" comment="">
|
||||||
|
<change afterPath="$PROJECT_DIR$/.idea/UNI_Python.iml" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/.idea/inspectionProfiles/Project_Default.xml" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/ha_04/loosen_janniclas_1540907_05.py" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/.idea/.gitignore" beforeDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/.idea/inspectionProfiles/profiles_settings.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/inspectionProfiles/profiles_settings.xml" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/.idea/jupyter-settings.xml" beforeDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/.idea/modules.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/.idea/python.iml" beforeDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/.idea/rGraphicsSettings.xml" beforeDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/.idea/rSettings.xml" beforeDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/ha_03/loosen_janniclas_1540907_04.py" beforeDir="false" afterPath="$PROJECT_DIR$/ha_03/loosen_janniclas_1540907_04.py" afterDir="false" />
|
||||||
|
</list>
|
||||||
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
|
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||||
|
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||||
|
</component>
|
||||||
|
<component name="Git.Settings">
|
||||||
|
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectId" id="2YitccTSlklP0ogYm4Iys53zq5P" />
|
||||||
|
<component name="ProjectViewState">
|
||||||
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
|
<option name="showLibraryContents" value="true" />
|
||||||
|
</component>
|
||||||
|
<component name="PropertiesComponent"><![CDATA[{
|
||||||
|
"keyToString": {
|
||||||
|
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||||
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
|
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
||||||
|
"WebServerToolWindowFactoryState": "false",
|
||||||
|
"git-widget-placeholder": "main",
|
||||||
|
"last_opened_file_path": "C:/Universitaet/UNI_Python",
|
||||||
|
"vue.rearranger.settings.migration": "true"
|
||||||
|
}
|
||||||
|
}]]></component>
|
||||||
|
<component name="RecentsManager">
|
||||||
|
<key name="MoveFile.RECENT_KEYS">
|
||||||
|
<recent name="C:\Universitaet\UNI_Python\ha_04" />
|
||||||
|
</key>
|
||||||
|
</component>
|
||||||
|
<component name="RunManager">
|
||||||
|
<configuration name="loosen_janniclas_1540907_05" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
|
||||||
|
<module name="UNI_Python" />
|
||||||
|
<option name="INTERPRETER_OPTIONS" value="" />
|
||||||
|
<option name="PARENT_ENVS" value="true" />
|
||||||
|
<envs>
|
||||||
|
<env name="PYTHONUNBUFFERED" value="1" />
|
||||||
|
</envs>
|
||||||
|
<option name="SDK_HOME" value="" />
|
||||||
|
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/ha_04" />
|
||||||
|
<option name="IS_MODULE_SDK" value="true" />
|
||||||
|
<option name="ADD_CONTENT_ROOTS" value="true" />
|
||||||
|
<option name="ADD_SOURCE_ROOTS" value="true" />
|
||||||
|
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
|
||||||
|
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/ha_04/loosen_janniclas_1540907_05.py" />
|
||||||
|
<option name="PARAMETERS" value="" />
|
||||||
|
<option name="SHOW_COMMAND_LINE" value="false" />
|
||||||
|
<option name="EMULATE_TERMINAL" value="false" />
|
||||||
|
<option name="MODULE_MODE" value="false" />
|
||||||
|
<option name="REDIRECT_INPUT" value="false" />
|
||||||
|
<option name="INPUT_FILE" value="" />
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
|
<recent_temporary>
|
||||||
|
<list>
|
||||||
|
<item itemvalue="Python.loosen_janniclas_1540907_05" />
|
||||||
|
</list>
|
||||||
|
</recent_temporary>
|
||||||
|
</component>
|
||||||
|
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
||||||
|
<component name="TaskManager">
|
||||||
|
<task active="true" id="Default" summary="Default task">
|
||||||
|
<changelist id="c8162e9c-0010-43df-bfbc-c294a3a64a5d" name="Changes" comment="" />
|
||||||
|
<created>1701020308079</created>
|
||||||
|
<option name="number" value="Default" />
|
||||||
|
<option name="presentableId" value="Default" />
|
||||||
|
<updated>1701020308079</updated>
|
||||||
|
<workItem from="1701020309178" duration="156000" />
|
||||||
|
</task>
|
||||||
|
<servers />
|
||||||
|
</component>
|
||||||
|
<component name="TypeScriptGeneratedFilesManager">
|
||||||
|
<option name="version" value="3" />
|
||||||
|
</component>
|
||||||
|
<component name="com.intellij.coverage.CoverageDataManagerImpl">
|
||||||
|
<SUITE FILE_PATH="coverage/UNI_Python$loosen_janniclas_1540907_05.coverage" NAME="loosen_janniclas_1540907_05 Coverage Results" MODIFIED="1701020433859" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/ha_04" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,163 @@
|
|||||||
|
# Author: Jan-Niclas Loosen
|
||||||
|
# Matrikelnummer: 1540907
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
|
||||||
|
# EXERCISE 1
|
||||||
|
class Rational:
|
||||||
|
numerator = 0
|
||||||
|
divisor = 1
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return "%d/%d" % (self.numerator, self.divisor)
|
||||||
|
|
||||||
|
def __init__(self, a=0, b=1):
|
||||||
|
if isinstance(a, Rational):
|
||||||
|
self.numerator = a.numerator
|
||||||
|
self.divisor = a.divisor
|
||||||
|
self.shorten()
|
||||||
|
elif isinstance(a, int) and isinstance(b, int):
|
||||||
|
if b == 0:
|
||||||
|
print("Divisor cannot be zero!")
|
||||||
|
exit(1)
|
||||||
|
if b < 0:
|
||||||
|
b = -b
|
||||||
|
a = -a
|
||||||
|
self.numerator = a
|
||||||
|
self.divisor = b
|
||||||
|
self.shorten()
|
||||||
|
else:
|
||||||
|
print("Numerator and divisor must be integer.")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
def gcd(self, a, b):
|
||||||
|
while b != 0:
|
||||||
|
(a, b) = (b, a % b)
|
||||||
|
return a
|
||||||
|
|
||||||
|
def lcm(self, a, b):
|
||||||
|
return abs(a * b) // self.gcd(a, b)
|
||||||
|
|
||||||
|
def lcd(self, other):
|
||||||
|
if not isinstance(other, Rational):
|
||||||
|
other = Rational(other)
|
||||||
|
return self.lcm(self.divisor, other.divisor)
|
||||||
|
|
||||||
|
def shorten(self):
|
||||||
|
d = self.gcd(self.numerator, self.divisor)
|
||||||
|
self.numerator = self.numerator // d
|
||||||
|
self.divisor = self.divisor // d
|
||||||
|
|
||||||
|
# addition
|
||||||
|
def __add__(self, other):
|
||||||
|
if not isinstance(other, Rational):
|
||||||
|
other = Rational(other)
|
||||||
|
|
||||||
|
lcm = self.lcm(self.divisor, other.divisor)
|
||||||
|
|
||||||
|
fac1 = lcm // self.divisor
|
||||||
|
fac2 = lcm // other.divisor
|
||||||
|
|
||||||
|
new_divisor = lcm
|
||||||
|
new_nominator = self.numerator * fac1 + other.numerator * fac2
|
||||||
|
return Rational(new_nominator, new_divisor)
|
||||||
|
|
||||||
|
def __radd__(self, other):
|
||||||
|
return self.__add__(other)
|
||||||
|
|
||||||
|
# subtraction
|
||||||
|
def __sub__(self, other):
|
||||||
|
if not isinstance(other, Rational):
|
||||||
|
other = Rational(other)
|
||||||
|
divisor_lcm = self.lcm(self.divisor, other.divisor)
|
||||||
|
new_nominator = (self.numerator * divisor_lcm / self.divisor) - (other.numerator * divisor_lcm / other.divisor)
|
||||||
|
return Rational(int(new_nominator), int(divisor_lcm))
|
||||||
|
|
||||||
|
def __rsub__(self, other):
|
||||||
|
if not isinstance(other, Rational):
|
||||||
|
other = Rational(other)
|
||||||
|
divisor_lcm = self.lcm(self.divisor, other.divisor)
|
||||||
|
new_nominator = (other.numerator * divisor_lcm / other.divisor) - (self.numerator * divisor_lcm / self.divisor)
|
||||||
|
return Rational(int(new_nominator), int(divisor_lcm))
|
||||||
|
|
||||||
|
# multiplication
|
||||||
|
def __mul__(self, other):
|
||||||
|
if isinstance(other, Rational):
|
||||||
|
return Rational(self.numerator * other.numerator, self.divisor * other.divisor)
|
||||||
|
else:
|
||||||
|
return Rational(self.numerator * other, self.divisor)
|
||||||
|
|
||||||
|
def __rmul__(self, other):
|
||||||
|
return self.__mul__(other)
|
||||||
|
|
||||||
|
# division
|
||||||
|
def __truediv__(self, other):
|
||||||
|
if not isinstance(other, Rational):
|
||||||
|
other = Rational(other)
|
||||||
|
new_numerator = self.numerator * other.divisor
|
||||||
|
new_divisor = self.divisor * other.numerator
|
||||||
|
return Rational(new_numerator, new_divisor)
|
||||||
|
|
||||||
|
def __rtruediv__(self, other):
|
||||||
|
if not isinstance(other, Rational):
|
||||||
|
other = Rational(other)
|
||||||
|
new_numerator = self.divisor * other.numerator
|
||||||
|
new_divisor = self.numerator * other.divisor
|
||||||
|
return Rational(new_numerator, new_divisor)
|
||||||
|
|
||||||
|
def __lt__(self, other):
|
||||||
|
divisor_lcm = self.lcd(other)
|
||||||
|
return (self.numerator * divisor_lcm / self.divisor) < (other.numerator * divisor_lcm / other.divisor)
|
||||||
|
|
||||||
|
def __gt__(self, other):
|
||||||
|
divisor_lcm = self.lcd(other)
|
||||||
|
return (self.numerator * divisor_lcm / self.divisor) > (other.numerator * divisor_lcm / other.divisor)
|
||||||
|
|
||||||
|
def __le__(self, other):
|
||||||
|
divisor_lcm = self.lcd(other)
|
||||||
|
return (self.numerator * divisor_lcm / self.divisor) <= (other.numerator * divisor_lcm / other.divisor)
|
||||||
|
|
||||||
|
def __ge__(self, other):
|
||||||
|
divisor_lcm = self.lcd(other)
|
||||||
|
return (self.numerator * divisor_lcm / self.divisor) >= (other.numerator * divisor_lcm / other.divisor)
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
if not isinstance(other, Rational):
|
||||||
|
other = Rational(other)
|
||||||
|
# all constructed Rationals are already shortened
|
||||||
|
return self.divisor == other.divisor and self.numerator == other.numerator
|
||||||
|
|
||||||
|
def __ne__(self, other):
|
||||||
|
return not self.__eq__(other)
|
||||||
|
|
||||||
|
|
||||||
|
# EXERCISE 2
|
||||||
|
def heron(a, x, run):
|
||||||
|
for i in range(run):
|
||||||
|
x = x - (x ** 2 - a) / (2 * x)
|
||||||
|
return x
|
||||||
|
|
||||||
|
|
||||||
|
# Generate x values
|
||||||
|
x_values = [x for x in range(10)]
|
||||||
|
|
||||||
|
# Calculate the difference between heron and sqrt functions
|
||||||
|
a = 2
|
||||||
|
b = 1.9
|
||||||
|
x0 = 1.5
|
||||||
|
|
||||||
|
y_values_a = [abs(heron(a, x0, run) - np.sqrt(a)) for run in x_values]
|
||||||
|
y_values_b = [abs(heron(b, x0, run) - np.sqrt(b)) for run in x_values]
|
||||||
|
|
||||||
|
# Plot the difference
|
||||||
|
plt.plot(x_values, y_values_a, label='a = 2, x0 = 1.5', color="blue")
|
||||||
|
plt.plot(x_values, y_values_b, label='b = 0.5, x0 = 1.5', color="red")
|
||||||
|
|
||||||
|
# Add labels and a legend
|
||||||
|
plt.xlabel('Iterations')
|
||||||
|
plt.ylabel('Difference')
|
||||||
|
plt.legend()
|
||||||
|
|
||||||
|
# Show the plot
|
||||||
|
plt.show()
|
Loading…
Reference in new issue