Lösung des mathematischen Mischungsproblems mit Python
Jan 12 2023
Ich bin auf ein mathematisches Problem für Mischungen gestoßen und habe darüber nachgedacht, wie ich die Lösung mit Python und Plots erklären kann. Das Problem ist: Sie erhalten einen Tank mit einem Gewicht von 20 Gallonen Mischung aus Öl und Wasser.
Ich bin auf ein mathematisches Problem für Mischungen gestoßen und habe darüber nachgedacht, wie ich die Lösung mit Python und Plots erklären kann. Das Problem ist:
Sie erhalten einen Tank mit einem Gewicht von 20 Gallonen Mischung aus Öl und Wasser. Der Ölanteil beträgt 40 %. Wasser wird zugegeben, um die Zusammensetzung auf 25 % Öl zu verdünnen.
a) Wie groß ist das Gesamtgewicht der verdünnten Mischung?
b) Wie viel Wasser wurde hinzugefügt?
Um das Problem zu lösen, schreiben wir zuerst die Bekannten auf.
import numpy as np
import matplotlib.pyplot as plt
orig_mix_weight = 20 # 20 gallons of original mixture
orig_mix_oil_per = 0.4 # percentage of oil in the original mixture
diluted_mix_oil_per = 0.25 # percentage of oil in the diluted mixture
# percentage of water in the original mixture
orig_mix_water_per = 1 - orig_mix_oil_per
orig_mix_water_per
0.6
water, oil = 10, 9 # Assume 10 represents water and 9 oil in the matrix
# create an array with water and oil as elements in the proportion
orig_mix = np.random.choice([water, oil],
size=(orig_mix_weight,),
p=[orig_mix_water_per, orig_mix_oil_per]) # probability
orig_mix = orig_mix.reshape(5, 4) # make it a 5x4 matrix for visualization
orig_mix
Image by author
[m,n] = np.shape(orig_mix)
plt.figure()
plt.imshow(orig_mix, alpha=0.8, cmap='Reds')
plt.xticks(np.arange(n))
plt.yticks(np.arange(m))
plt.title('Original Solution')
plt.show()
Image by author
orig_mix_oil_weight = orig_mix_weight * orig_mix_oil_per
orig_mix_oil_weight # weight of oil in original mixture
8.0
diluted_mix_oil_weight = orig_mix_oil_weight
diluted_mix_oil_weight # weight of oil in diluted mixture
8.0
diluted_mix_alcohol_per = 0.25
diluted_mix_weight = 1 / diluted_mix_oil_per * diluted_mix_oil_weight
diluted_mix_weight
32.0
diluted_mix_water_per = 1- diluted_mix_alcohol_per
diluted_mix = np.random.choice([water, oil],
size=(int(diluted_mix_weight),),
p=[diluted_mix_water_per, diluted_mix_alcohol_per])
diluted_mix = diluted_mix.reshape(8, 4) # make it a 5x4 matrix for visualization
[m,n] = np.shape(diluted_mix)
plt.figure()
plt.imshow(diluted_mix, alpha=0.8, cmap='Reds')
plt.xticks(np.arange(n))
plt.yticks(np.arange(m))
plt.title('Diluted Solution')
plt.show()
Image by author
diluted_mix_weight - orig_mix_weight
12.0
![Was ist überhaupt eine verknüpfte Liste? [Teil 1]](https://post.nghiatu.com/assets/images/m/max/724/1*Xokk6XOjWyIGCBujkJsCzQ.jpeg)



































