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 🙂
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.
What you want is perfectly possible.
Suppose the equation is
Then you define it e.g. with:
(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.
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.
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.
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:
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.
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.
"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.
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?
"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?"
Although I in general advise against that, you could try to add a numerical evaluation (just: 😃 to the end of the definition of the functions Get_f(). See attchment "...Example3".
When you define two functions with the same name, but een different number (or a different set) of parameters, Mathcad, nor Prime, can guess which function you want to use, based upon the number of parameters. It simply uses that last preceding definition of the named function and produces an error message if necessary. As you found out the hard way.
But even in text books If you have multiple equations that use the same variable (name), you HAVE to reference the equation to use when calculating that variable from an equation. Example:
If you want to calculate the pressure (P) from the ideal gas law, you have to indicate that. For example with :
From equation 1 as "PEq1(n,T,V), or using the ideal gas law as "Pidealgas(n,T,V)" or by indexing P, such as: "Pn,T,V(n,T,V)".
You can do that in Prime also, see attachment "...Example2".
It is a bit cunbersome to get the comma's in the function name, but it can be done as follows:
Type a string with the function name: "f,,,"
Then delete the (first or last) quote, the string contents changes to a variable.
Now you can put the intervening text: before the first comma type [CTRL-_ ] n (That's Control and Underscore) and then n.
Then after the first undersore type [CTRL-_ ] R1.
And so on for the rest.
Then you can add the parenteses by typing (: at the end.
Then fill in the rest.