cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

Type equation first then evaluate with values

Dan888
1-Newbie

Type equation first then evaluate with values

I'd like to type something like this:

Area = a x b

where:

a := 10

b := 20

Thus,

Area = 200

How close can I get in Mathcad?

I've tried using the boolean "=" for the first statement but then can't get the last statement to work.

16 REPLIES 16
Fred_Kohlhepp
23-Emerald I
(To:Dan888)

Mathcad evaluates top down and left to right.

type a : 10 (the : will become :=)

type b : 20

This will define a and b as equal to those values.

Below, or to the right type

Area: a * b =

see attached.

Werner_E
24-Ruby V
(To:Dan888)

Fred showed you one way to do it.

If you insist in having the formula on top, you have to define it as a function depending on the two arguments.

I have chosen the names "length" and "width" to make clear that the can be different from the variable names you use later. But of course the arguments can be named a and b, too, if you like.

1.png

An alternative way would be the use of global assignments, but I would strongly advise against using them.

2.png

Here is the image which does not show in the previous post. I ever so often have this problem that when I edit a post I am not able to add images.

2.png

Werner Exinger wrote:

Here is the image which does not show in the previous post. I ever so often have this problem that when I edit a post I am not able to add images.

2.png

SMath. Is it good?

SMathArea.png

If you want the structure you've given, then the definition of Area needs to be a function, as shown below.

type_first.png

Dan888
1-Newbie
(To:Dan888)

Thanks, but is there no way to do it with booleans / symbolics?

Seems a bit of an oversight if not as it is the way most solutions / books are written.

Functions are a bit "mathy" in my context.

RichardJ
19-Tanzanite
(To:Dan888)

It's not an oversight, it's by design. A book doesn't have to calculate anything. Suppose on page xxx I have:

a:=2

b:=3

Area:=a*b

So Area=6

Then on page xxx+5 I have:

If a and b now take on the new values

a:=4

b:=5

then Area=20.

You can understand that, but for Mathcad to know that the latter two values should be used it would have to understand the text. The way Mathcad treats it is that Area is a fixed quantity calculated from previously declared values. What you are asking for is that Area is an implicit function. In the example I give above, it would actually have to be both, depending on context that is only clear from the text.

Valery shows an example from Smath, where you can do what you request (although not the example I show). What he doesn't say is that the help (or perhaps a tutorial?) warns you it's a dangerous thing to do, because you can get unexpected results.

Fred_Kohlhepp
23-Emerald I
(To:Dan888)

Tip of the hat to Valery, we can give you exactly what you want with a bit of hidden magic.

Took me a while to figure out what you did there Fred !

Note to all: There's an area at the top where a and b are defined.

Dan888
1-Newbie
(To:Dan888)

Is there a way to do it with solve blocks?

I tried the following but it doesn't give an answer: (all equals in the solve block are boolean)

Area := 50 (guess value)

Given (start solve block)

Area = a.b

a = 10

b = 20

Find(Area) =

MikeArmstrong
5-Regular Member
(To:Dan888)

Yes, but why would you want to?

Werner's example above basically does the same.

Werner_E
24-Ruby V
(To:Dan888)

Dan Rose wrote:

Is there a way to do it with solve blocks?

I tried the following but it doesn't give an answer: (all equals in the solve block are boolean)

Area := 50 (guess value)

Given (start solve block)

Area = a.b

a = 10

b = 20

Find(Area) =

You can make it work if you use the normal assigment (:=) for a nd b. But I wonder what the sense of this should be. As far I understood that you want it to look like your example in your first post. And the only reason for this I can think of is, that its for documentation purposes.

And if defining Area as a function is not a solution because it look too mathematical, what does the solve block looks like?

I guess using hidden areas might be a solution.

One solution, which is still dynamic with respect to a and b (but not wrt the formula at the top) is as follows

1.png

If you don't mind the red error (which is thrown by the numerics) und using the symbolics you can even make the formula at the top dynamic (a and b must not be defined before the definition at the top.

2.png

You probably know that you can make all the various equal signs (boolean, assignment, even the symbolic eval) look like a normal equal sign by using the right clik menu if thats the preferred representation.

For your second example, I've just learnt on another thread that you can put:

a:=1

a:=a

b:=1

b:=b

at the top and it will get rid of the red error.

It is just for documentation purposes. I'm in engineering and you generally derive your equation first and then input the values. I'm pretty new to Mathcad so just trying to find its limits.

Werner_E
24-Ruby V
(To:Dan888)

Dan Rose wrote:

For your second example, I've just learnt on another thread that you can put:

a:=1

a:=a

b:=1

b:=b

at the top and it will get rid of the red error.

Yes, and Area will be 1 no matter what values you assign later for a and b. So it doesn't seem to be a good idea if the goal is a live dynamic worksheet.

It works OK - see attached.

Werner_E
24-Ruby V
(To:Dan888)

Oh I see, you are right!

Top Tags