[✓] Treat indexed objects as variables?

GROUPS:
 It seems Mathematica doesn't recognize a[1] + 1 like the same variable a[1] plus one: a[1] = \[Omega] a[2] = l V[x_, a[1], a[2]] := 1/4*a[1]^2*x^2 + a[2]*(a[2] + 1)/x^2 V[x, a[1] + 1, a[2]] 
10 months ago
9 Replies
 Sander Huisman 1 Vote V[x, a[1] + 1, a[2]] simply does not match the pattern: V[x_, a[1], a[2]] I think you want: ClearAll[V] V[x_, a1_, a2_] := 1/4*a1^2*x^2 + a2*(a2 + 1)/x^2 
10 months ago
 I defined a[1] instead of a1 cause later i have to call it with a[i] where i=1 or 2 and it seems it doesnt work with ai
10 months ago
 V[x, a1, a2_] := 1/4a1^2x^2 + a2*(a2 + 1)/x^2this function can still 'receive' a[1] or a[2] as an argument, a1 and a2 are just temporary names…If that doesn't work for some reason; you can also make definitions with more elaborate patterns: V[x_, a_[y_], b_[z_]] := ... 
10 months ago
 Thank you but it seems it doesn't work. What i would like to do is this: a[1][\[Omega]_] = \[Omega] a[2][l_] = l V[x_, a_[1], a_[2]] := 1/4*a[1]^2*x^2 + a[2]*(a[2] + 1)/x^2 V[x, a[1] + 1, a[2]] This works, but after i found a k value (like k=1) i would be able to eliminate a[2] dependence from V, defining a new function. k := 1 G[x_, a_[k]] := V[x, a[1], a[2]] G[x, a[k] + 1] This doesn't work
10 months ago
 That first example does NOT work. What is k? To make this question/topic useful explain what you want to do, your input, and the expected output as simple as possible.
10 months ago
 You're right. So i have 2 problems. Do you have an idea? k is a value i found with an algorithm that gives me the right parameter a[1] or a[2]
 I tried that but i can't do something like this Q[x_,a[k]_]:=V[x,a[k]+c]-V[x,a[k]]