Robert Seifert
Robert Seifert

Reputation: 25232

Display expression and result of calculation in MuPad

Imagine I define two variables within a MuPad Notebook:

x:=2;
y:=5

For the product

z=x*y

I get displayed:

enter image description here

And if I use hold, I can get the expression:

z=hold(x*y)

enter image description here

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);

enter image description here

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

Answers (1)

Matt
Matt

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.

Assignment vs. Equation

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)

result1

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)

result2

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))

result3

Upvotes: 2

Related Questions