Compiling and assigning result of multiline function
See original GitHub issueHi! I’m trying to move from Mathcad to Calcpad, since this is an amazing and fast software. I have a function that has an if condition inside for calculating an effective moment of inertia. This is what I want to do in Calcpad:
And this is what I managed to do:
But I can’t assign the function result to a variable when compiling. This is what I get: And if I put it in the same line:
I would like to run this function for many values of Ma and assign it to different variables or just the function inside an equation, like this:
What I managed to do is this:
#def Ie$(Mcr$; Ma$)
#if Ma$ ≤ 2/3*Mcr$
Ie = I_g
#else
Ie = I_cr/(1 - (2/3*Mcr$/Ma$)^2*(1 - I_cr/I_g))
#end if
#end def
Ie$(M_cr; M_pp)
I_e.pp = Ie
It does the trick but doesn’t look quite good. And I can’t get to hide the result of the if equation with #hide and #show.
Also, is there a way to make AutoRun work when working with functions? Because now I have to compile the inputs and then the outputs. Thanks for the help!
Issue Analytics
- State:
- Created 7 months ago
- Comments:8 (2 by maintainers)
Top GitHub Comments
As @hildebrandopsj already replied, you should use the #if statement instead.
In general, math functions do not work with strings, but you can define string functions, called “macros”. Their names must end with $. For example, you can create an inline function, similar to if() to handle your case:
Then, you can use it like that:
Macros are very powerful to mix strings with expressions. You can use them to create your own macro extension to the Calcpad language that automates specific tasks. For example, I made this to easy draw svg images with lines, circles, texts and dimension lines:
https://gist.github.com/Proektsoftbg/1f16d0f85e1007266455177f159eef23
And this is how the result looks:
The drawing is parametrically dependent on the input data, not just a static picture. I am also experimenting with generation of AutoCAD script files from Calcpad in a similar way.
Hi, use the If() function:
f(x; y) = if(x<y; x; y)