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
- :
- Re: "Automated" symbolic and quantitative calculat...

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- 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
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

06-29-2020
11:38 AM

06-29-2020
11:38 AM

"Automated" symbolic and quantitative calculations

Hi,

Very new user of MathCad here, so I really need some help.

I am trying to create a *continuous* worksheet with geometrical optics formulas and calculations. Basically, I would like to have a bunch of formulas defined in the first pages of the worksheet (with comments, etc.), and then to have sections with calculations for various cases. For example, say I define the lensmaker's equation, and then 10 pages later I would like to have a calculation where all the variables are defined and MathCad would give the correct value for lens power. I understand that this is pretty straightforward, I could just use global definition for the equation, then define each parameter, and finally evaluate the result. And if I am not mistaken, I could also do this multiple times in the same worksheet, that is globally define the equation in the beginning and then define parameters for various cases and evaluate the result for each one.

But the thing is that I would also like to be able to calculate other values of the formulas, for example for the lensmaker's equation I would like to be able to evaluate R1 given all the other parameters including power/focal length. And I would like to do that without having to re-define the formula if possible, neither on the particular case I am calculating nor in the "formula's section" in the beginning of the worksheet. So, basically I would like to automate in a sense the calculations for my needs.

I understand that MathCad uses symbolic calculations for something like I am asking for but playing around with it a bit I didn't manage to get what I want, nor I was successful in searching for the solution online.

I hope I managed to communicate my problem clearly. I would appreciate any help 🙂

Thanks

Labels:

12 REPLIES 12

Highlighted
##

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

06-30-2020
03:20 AM

06-30-2020
03:20 AM

Re: "Automated" symbolic and quantitative calculations

You may define the equation in the front and then let Mathcads symbolic create functions for each variable depending on the other variables in use.

Later you may use those function as you need.

Here an example with a simple equation.

Some more work may be necessary if your function can't be that easily and unambiguously for a specific variable.

Highlighted
##

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

06-30-2020
03:26 AM

06-30-2020
03:26 AM

Re: "Automated" symbolic and quantitative calculations

What you want is perfectly possible.

Suppose the equation is

a=b+c

Then you define it e.g. with:

Equ:=a=b+c

(Where you make sure that the = between a and b is a bold one)

Then you can define:

a(b,c):=Equ -> solve, a

(Where -> solve is a symbolic command)

And you can define:

b(a,c):=Equ -> solve, b

If you need help, post your worksheet with any questions you may have.

Success!

Luc.

Highlighted
##

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

06-30-2020
03:37 AM

06-30-2020
03:37 AM

Re: "Automated" symbolic and quantitative calculations

As shown in my example above I wouldn't name the function a,b,c because this may interfere with variables of the same name. Its possible to have functions and variables with the same name side by side using different styles/labels, but doing so sure is more cumbersome.

Highlighted
##

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

06-30-2020
03:56 AM

06-30-2020
03:56 AM

Re: "Automated" symbolic and quantitative calculations

Considering that the OP wants a generally usable worksheet, I'd suggest the variables are named with a specific identifier (not a, but a.left for example) instead of the functions.

Luc

Highlighted
##

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

06-30-2020
07:44 AM

06-30-2020
07:44 AM

Re: "Automated" symbolic and quantitative calculations

DO NOT use a global equals sign in a function definition! It doesn't add anything useful. In fact you should avoid (as much as possible) using the global equals sign--they tend to cause more problems than they're worth.

In addition to Luc's suggestion for using the symbolic processor, you can find the value required in a function (knowing all of the others and the desired result) using a solve block. (Solve blocks only work in full Prime; since I have only Express I cannot supply an example.) The root function can also be used to do this * for some functions*:

Highlighted
##

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

06-30-2020
08:25 AM

06-30-2020
08:25 AM

Re: "Automated" symbolic and quantitative calculations

I would like to thank you both for your replies.

As you can see in the attached file, with your help I managed to proceed quite a bit (for me).

But other problems arose.

Structure of the worksheet: First there is a very simple formula defined and then the "equivalents" are calculated symbolically as per your advice. Then another formula is defined, *one whose variables contain the same variable as the first formula, *and again the variables are calculated symbolically. Finally, 2 parameters are defined and the quantitative calculation of the first equation is attempted.

The problems are:

1) The f_number variable in the beginning "is undefined". I don't know if this is important or what problems it may cause later but even it is not dangerous I would like to remove it if possible. If not, that's ok. The same with "f" in the second equation.

2) Most important: the calculation in the end cannot be performed. It asks for 4 variables (due to the second defined equation I suppose) *but I want to use the first equation where 2 variables are enough*. Note, that if I move this calculation in the space between the two equations it works fine. So, is MathCad able to go around this? As I said in my original post, I would like to have all equations defined in the beginning (and most of them would be intertwined like the case in the worksheet) and then define parameters and calculate accordingly.

3) If possible, I would like to not have to name each defined equation. This will make it hard to remember the names after a while, and also it would make it hard for other people to use this file. Would it be possible to just define the equation?

4) In this structure, all equations are effectively not defined once but rather as many times as the number of variables contained in them. Maybe I am asking a lot but is there a way to define each equation only once? This basically goes together with number 3, it's just for elegance, readability and ease of use of the file. If not, the way it is now would do I suppose.

Thank you in advance, I really appreciate your help.

Antonis

Highlighted
##

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

06-30-2020
11:24 AM

06-30-2020
11:24 AM

Re: "Automated" symbolic and quantitative calculations

In Prime there seems to be nothing you can do against the "variable not defined" error when you define your equations. But this error does not influence the result in any way.

You define quite a couple of functions, all with the same name "get_f". Only the last function definition "wins", the others are overwritten. Also the function arguments in your functions are wrong. E.g. you last function should not read "get_f(n,f,R2,d):=..." but rather "get_d(n,f,R1,R2=:_..."

You solve two different equations for f. You can't name the functions the same and hope that Prime will use the correct one. You have to name them differently, like "get_f1(..)" and "get_f2(..)=".

Its not clear to me what you mean by " just define the equation". When you want the symbolic to solve an equation for n, f, R1, etc. you have to tell the symbolic somehow which equation it should use. I guess its easier to assign the equations to variables as the alternative would be to retype (or copy) the equation for every solve expression.

Highlighted
##

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

07-02-2020
11:10 AM

07-02-2020
11:10 AM

Re: "Automated" symbolic and quantitative calculations

Hi,

"You solve two different equations for f. You can't name the functions the same and hope that Prime will use the correct one. You have to name them differently, like "get_f1(..)" and "get_f2(..)="."

I was really hoping that MathCad would be able to handle this, perhaps by recognizing which parameters are given in a function and using the appropriate defined formula.

So what happens if you have a bunch of equations to define and all of them have shared parameters?

You would have to define say, get_f1, get_f2, get_f3, get_f4, and then to define say get_R1 *for each **f already defined*. Which is inefficient to say the least and basically defeats the purpose of what I want to create.

Or there is something I don't quite understand. Any ideas?

"I guess its easier to assign the equations to variables as the alternative would be to retype (or copy) the equation for every solve expression."

I am not sure what you mean by that.

Highlighted
##

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

06-30-2020
01:00 PM

06-30-2020
01:00 PM

Re: "Automated" symbolic and quantitative calculations

Symbolics is another thing that Express won't do.

But using the root function and a single function we can still prevail

Highlighted
##

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

07-02-2020
10:58 AM

07-02-2020
10:58 AM

Re: "Automated" symbolic and quantitative calculations

For some reason I am not able to download your file.

Highlighted
##

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

07-02-2020
12:19 PM

07-02-2020
12:19 PM

Re: "Automated" symbolic and quantitative calculations

PDF attached.

Made in Prime 6 Express, Prime 6 should have openedf it.

Highlighted
##

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

07-03-2020
06:04 AM

07-03-2020
06:04 AM

Re: "Automated" symbolic and quantitative calculations

So, after the above replies, I suppose the request in my original post needs to be shifted to this:

Is there a way in MathCad to define multiple equations with intertwined parameters, and depending on the given parameters for a particular case the appropriate equation would be used? For example, in the attached file ("example 2") I would like to be able to calculate a specific variable irrespective of the fact that other formulas have been defined for the same variable. Perhaps with a solve block or something? Or maybe I am asking too much..

Or another solution would be to define all the formulas in the beginning and then, depending on what I need on the particular case, to use symbolics to calculate it. That way I would have to go back and search for the appropriate formula to solve, but I think I can live with that. Only thing I don't like ("example 3") is that I have to use two lines for each calculation, one for the symbolics and one for the quantitative. Is there a way to do all of this in one line?

Thank's.