Reputation: 25232
Imagine I define two variables within a MuPad Notebook:
x:=2;
y:=5
For the product
z=x*y
I get displayed:
And if I use hold
, I can get the expression:
z=hold(x*y)
But now I'd like to have both, the expression displayed and the result. The two options which appeared logical to me, do not worK:
z=hold(x*y);z
and
z=hold(x*y);eval(z);
How can I get displayed the expression AND the result? If in two lines it would be alright, but I'd prefer in one line like:
z = x y = 10
Upvotes: 2
Views: 190
Reputation: 13943
I tried some combinations with print
, expr2text
, hold
and _concat
but couldn't find a convincing solution to get the desired result. But there is an explanation why the second line just returns z
and not 10
.
z
is the result in the second line because you didn't assign something to z
yet. So the result says that z
is z
. In MuPad =
is part of an expression. The assignment operator is :=
and therefore not the same as in Matlab. The only difference between them is the colon.
Writing an equation
For writing an equation, we use =
as part of the expression. There is an equivalent function: _equal
. So the following two lines generate the same result:
x+y = 2
_equal(x+y, 2)
Assign value
to x
For an assignment we use :=
(in Matlab this would be only =
). There is an equivalent function: _assign
. So again, the following two lines generate the same result:
x := value
_assign(x, value)
Assign the equation x+y = 2
to eqn
Here we can clearly see the difference:
eqn := x+y = 2
_assign(eqn, _equal(x+y, 2))
Upvotes: 2