Message Boards Message Boards

0
|
4567 Views
|
2 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Understand the meaning of & operator?

Posted 5 years ago

Hi there,

A simple problem appeared and I can't solve it by myself. Plese don't focus on the meaning of the functions and of the values assigned to variables: I suspect the problem is on how I treat aa and bb.

After defining the following functions XX and Hvv that I can call in the code:

XX = -Inverse[aa].(bb.UU );

Hvv = cc.(Inverse[s i - aa].bb);

If I call

X=XX&[aa=4,bb=5,cc=6]

and then call Hvv

Hv=Hvv&[aa=6,bb=7]

I get wrong values for Hv.

But if after calling X=XX&(ecc.) I re-evaluate the definition of Hvv = cc.(Inverse[s i - aa].bb) then everything is fine if I call now Hv=Hvv(ecc.).

I guess I'm misunderstanding the meaning of f(aa)&(aa=a) which I intend as "evaluate f ifor aa=a".

You guys have insight on how to solve this? Thanks.

POSTED BY: Ermanno Citraro
2 Replies

Thanks a lot. I'm learning Mathematica bit by bit so I do not have the general picture. Now I know how to define and call proper functions and the code works fine.

What I did until know (and worked until now) was declaring variables (dependent "functions") which depended on other variables (independent variables) and then evaluate the dependent ones using & operator on the independent.

POSTED BY: Ermanno Citraro
Posted 5 years ago

Are you able to provide a minimal example with code one could actually evaluate?

I think there are some fundamental issues in your syntax. For example to define a function XX with 3 arguments you would want to instead do

XX[aa_, bb_, UU_] := -Inverse[aa].(bb.UU )

or something similar. The following doesn't really make a ton of sense:

XX = -Inverse[aa].(bb.UU );
X=XX&[aa=4,bb=5,cc=6]

Consider this documentation page: https://reference.wolfram.com/language/tutorial/DefiningFunctions.html

POSTED BY: Kyle Martin
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