Message Boards Message Boards

0
|
2322 Views
|
5 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Using indexed variables in defining a function

Posted 1 year ago

I am stuck in defining a function using indexed arguments.

Let's say

V[Subscript[x, 1],Subscript[x, 2]]=5Subscript[x, 1]^2+2Subscript[x, 1] Subscript[x, 2]+Subscript[x, 2]^2

Actually, I can't figure out where to put the underscore sign of the arguments, like in

f[t_]:=2t+1
POSTED BY: Mohand Amyis
5 Replies
Posted 1 year ago

If the subscripts are just a naming convention for your arguments, then you're better off just using x1 and x2:

V[x1_, x2_] := 5 x1^2 + 2 x1 x2 + x2^2

If you're using subscripts to index into an array/matrix structure or for some other semantic, then we need more information about your context to be able to provide guidance.

POSTED BY: Eric Rimbey
Posted 1 year ago

Thank you for your answer. Actually, this is just a naming convention for the arguments of the function and it is to mimic equations given in textbooks. It should be interesting to get to it though.

POSTED BY: Mohand Amyis
Posted 1 year ago

Well, you won't get it to work, unless I'm entirely misunderstanding your question. If you want to use Pattern to name the arguments to your function definition, then you need to use symbols for the name. Thus you can't name your patterns with things like Subscript[x,1].

POSTED BY: Eric Rimbey
Posted 11 months ago

I am back to the problem I submitted 8 months ago. I think I found a solution. Please, take a look at the file attached. By the way I am using Mathematica 13.3.

Attachments:
POSTED BY: Mohand Amyis

The Symbolize function is tricky. Try this:

V[x\[UnderBracket]Subscript\[UnderBracket]1, 0] - 5 Subscript[x, 1]^2

x\[UnderBracket]Subscript\[UnderBracket]1 and Subscript[x, 1] are different objects but look exaclty the same in the FronEnd. You must be careful when composing your formulas.

POSTED BY: Gianluca Gorni
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