Don't know python - do i and j start from 0?Hello,
I have been trying to find the density of a fluid which is a function of concentration x and temperature t, the empirical correlations looks as this;
View attachment 25382
I tried to solve this using a simple Python code but I can not get it right, anyone that can see my mistake?
View attachment 25383
Kind regards,
/M
I know Python, and yes variable i will iterate through all the values from 0 up to (rows-1) inclusively. So it will take values {0,1,2} rather than {1,2,3}.Don't know python - do i and j start from 0?
Is rows 2 or 3?I made the change but still do not get it to work, have I missunderstood the double summation part maybe?
Rows and columns are 3, it is basically the table 3 as a 3x3 matrix.Is rows 2 or 3?
Then your loops iterate 4 times instead of 3.Rows and columns are 3, it is basically the table 3 as a 3x3 matrix.
No there go 0,1,2 and stop so i=j=2 at the final iteration; I can copy-paste the codeThen your loops iterate 4 times instead of 3.
Sorry, should've looked up the syntax.No there go 0,1,2 and stop so i=j=2 at the final iteration; I can copy-paste the code
import numpy as np
A_1_1 = 1.0004 #i = 1, j=1
A_1_2 = 1.7659 * (10**-1) #i=1, j=2
A_1_3 = -4.9214 * (10**-2) # i=1, j=3
A_2_1 = -1.2379 * (10 **-4) # i=2,j=1
A_2_2 = -9.9189* (10**-4) # i=2, j=2
A_2_3 = 4.1024 * (10 **-4) # i=2, j=3
A_3_1 = -2.9837 * (10 **-6) #i=3,j=1
A_3_2 = 2.4614 * (10**-6) # i=3, j=2
A_3_3 = -9.5278 * (10**-8) # i=3, j=3
A = np.array([[A_1_1,A_1_2,A_1_3],[A_2_1,A_2_2,A_2_3],[A_3_1,A_3_2,A_3_3]])
rows, cols = A.shape
density = 0
X=0.75
t=155
SUM = 0
for i in range(0, rows):
for j in range(0, cols):
SUM += A[j] * X**j * t**j
Yes I get the wrong results, so it might be that I am calculating/using the correlation wrongSorry, should've looked up the syntax.
When you say it doesn't work, what exactly do you mean? Wrong result is produced?
Can you use a debugger? If not - replace all values by something easy to deal with: 0 or 1. I would start with 1 for x and t and a bunch of 0s and 1s in the matrix so you could easily calculate the result. If you get what's expected start gradually using actual values.Yes I get the wrong results, so it might be that I am calculating/using the correlation wrong
I tried that. I think there is something wrong with the correlation that have been published. I get right values for low temperatures (t) /concentrations (X) but very wrong when they are chosen in the higher part of the allowed interval in which the correlation should be valid. Very strange!Can you use a debugger? If not - replace all values by something easy to deal with: 0 or 1. I would start with 1 for x and t and a bunch of 0s and 1s in the matrix so you could easily calculate the result. If you get what's expected start gradually using actual values.