Alternative Lösung mit reinem Numpy

This commit is contained in:
Sandro Zimmermann 2026-10-05 21:32:58 +02:00
parent d190458950
commit abbafab0b3

View File

@ -54,7 +54,7 @@ d = Vector([1.0, 0.32])
operations = [
lambda: 4 * a + 2.1 * (b * c),
lambda: -8.35 * (a.cross(c) * b - abs(d) ** 2),
lambda: -8.35 * a.cross(c) * b - abs(d) ** 2,
lambda: (3.1 * d).cross(a) - (a * 2 * c) * b,
lambda: a * (1 / abs(d)) - (2 * b - 9.33 * c),
]
@ -64,3 +64,28 @@ for operation in operations:
print(operation())
except Exception as e:
print(f"Error: {e}")
#%%
import numpy as np
a = np.array([3.8, 2.12, -4.01])
b = np.array([0.01, -0.02, 2.341])
c = np.array([-5.1, 1.0, 4.5])
d = np.array([1.0, 0.32])
# 4 * a + 2.1 * (b @ c) is mathematically not defined, but numpy will run it anyways, becaus it fills array fiels with 0. Native numpy can't catch this error
operations = [
lambda: 4 * a + 2.1 * (b @ c),
lambda: -8.35 * np.cross(a, c) @ b - np.linalg.norm(d) ** 2,
lambda: np.cross(3.1 * d, a) - (a @ (2 * c)) * b,
lambda: a * (1 / np.linalg.norm(d)) - (2 * b - 9.33 * c),
]
for operation in operations:
try:
print(operation())
except Exception as e:
print(f"Error: {e}")
# %%