Get Help

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community
- :
- PTC Mathcad
- :
- PTC Mathcad
- :
- Type equation first then evaluate with values

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

08-29-2014
09:38 AM

08-29-2014
09:38 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

08-29-2014
09:45 AM

08-29-2014
09:45 AM

Re: Type equation first then evaluate with values

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

08-29-2014
09:54 AM

08-29-2014
09:54 AM

Re: Type equation first then evaluate with values

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.

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

08-29-2014
09:55 AM

08-29-2014
09:55 AM

Re: Type equation first then evaluate with values

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

08-29-2014
09:59 AM

08-29-2014
09:59 AM

Re: Type equation first then evaluate with values

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

08-29-2014
10:00 AM

08-29-2014
10:00 AM

Re: Type equation first then evaluate with values

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

08-29-2014
10:11 AM

08-29-2014
10:11 AM

Re: Type equation first then evaluate with values

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

08-29-2014
03:05 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

08-29-2014
06:55 PM

08-29-2014
06:55 PM

Re: Type equation first then evaluate with values

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-01-2014
02:59 AM

09-01-2014
02:59 AM

Re: Type equation first then evaluate with values

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.

Top Tags