Message Boards Message Boards

0
|
3061 Views
|
9 Replies
|
1 Total Likes
View groups...
Share
Share this post:

[?] Treat indexed objects as variables?

Posted 7 years ago

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]]
POSTED BY: deimos1990
9 Replies
Posted 7 years ago

I tried that but i can't do something like this

Q[x_,a[k]_]:=V[x,a[k]+c]-V[x,a[k]]
POSTED BY: deimos1990
Posted 7 years ago

Ok sorry... i try to explain it. I have a function V depending from x and some parameters a[i]. After an algorithm i found the parameter that needs to be modified and so i found a value for k. Next i have to eventually substitute a[k] with a[k] + c for any value of k and so i thought to define a new function G depending only of x and a[k]

POSTED BY: deimos1990

That is a bit more clear. Still not very… have a look at Replace and ReplaceAll.

POSTED BY: Sander Huisman
Posted 7 years 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]

POSTED BY: deimos1990
Posted 7 years 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

POSTED BY: deimos1990

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.

POSTED BY: Sander Huisman
Posted 7 years 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

POSTED BY: deimos1990

V[x, a1, a2_] := 1/4a1^2x^2 + a2*(a2 + 1)/x^2

this 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_]] := ...
POSTED BY: Sander Huisman
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
POSTED BY: Sander Huisman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract