1

I am going to define a set of dynamic variables like X1, X2,..., Xd (which d = dimension is the input and is not a fixed number) and allocate this unknowns to a C(1,d) vector. It is supposed that the matrix multiplication of this (1,d) vector of unknowns in a B(d,d) matrix (all elements are known in B) gives me 'd' equations that I can solve for those 'd' unknown variables. Simply speaking, 'd' equations, 'd' unknowns.

In Matlab, there was a kind of solution like ['X' num2str(i)] to define the variables dynamically, but I could not find any way in python.

I would think there is a way to define dynamic variables, so I could write:

C = np.ones((d,1))
C = (1/d)* C

for i in range (0,d):
    C[i] = C[i] * X(i)

for j in range (0,d):
        for i in range (0,d):
            eq(j) = sum(C[i]*B[i][j])

But as it turns out, such a way to define dynamic variables is not allowed and makes problems in producing X[i]s and allocating them to C[i]s as well as in numbering the equations eq[j]s. Thanks for your suggestions, but they are not applicable in my question.

What you have referred me to are all for the case that I want to assign a beginning value to these variables. Actually, these are functions which their type should float because they are supposed to be allowed for multiplying to other numbers but still should not have a value. I hope you understand what I mean. For example think we have two equations (x+y-3=0) and (x+3y-2=0). You can not allocate some initial value to the defined variables, because it scrows up your set off equations. Here I need a set of dynamically named functions based on my input 'd' which defines how many of these equations will be built. As you can see in the last set of nested for(s), the 'd' specifies the number of equation which will be built. I CAN NOT allocate a number to those space holders while they should be known as floats to be able to multiply and add them to numbers in my matrices. And I need d number of these so-called variables. That is why I have written it should be produced during the runtime. Please don't superscribe this post directly as duplicate.

Mahdi
  • 11
  • 2
  • I agree on not being a duplicate, as in your case all variables are of same type and a [list](https://www.tutorialspoint.com/python/python_lists.htm) of numbers (vector `C`) or a list of list of numbers (matrix `B`) appears more appropriate than the dictionary proposed in the 'duplicate' to me... – Aconcagua Sep 08 '19 at 05:11

0 Answers0