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

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

Subroutine

ssato
14-Alexandrite

Subroutine

Hello everyone

 

 Please tell me how to use MATHCAD15 to describe a solve block and a block to be calculated

using the result of this solve block as a subroutine or a function and use it repeatedly.

 

I have found this answer below, I want to do this.

 

But is it the same for the latest MATHCAD15?

 

https://community.ptc.com/t5/PTC-Mathcad/Subroutine/m-p/43405#M17455

 

With this method, if I modify only a part of the part that I made a subroutine, will it be the following method?

 

(1) Open each area and modify the same corresponding parts

(2) After correcting in one area, copy this area, delete the other uncorrected area,

and paste and replace the copied area.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Werner_E
24-Ruby V
(To:ssato)


@ssato wrote:

Hello everyone

 

 Please tell me how to use MATHCAD15 to describe a solve block and a block to be calculated

using the result of this solve block as a subroutine or a function and use it repeatedly.

 

Simply turn the solve block into a function depending on the various input variables you'd need by writing

f(in1,in2,...):=Find(out1,out2,....)

at the end of the solve block instead of just

out:=Find(out1,out2,...)

 


 

I have found this answer below, I want to do this.

The thread in the link you provided deals with a different problem as far as I can tell. Here someone asked for how to turn a whole sheet into a function - a feature still not provided by Mathcad.

The suggestion just was to hide the calculation which should have been done in a separate sheet in a collapsed region to make the worksheet look as clean as if the calculation was done somewhere else.

 


With this method, if I modify only a part of the part that I made a subroutine, will it be the following method?

 

(1) Open each area and modify the same corresponding parts

(2) After correcting in one area, copy this area, delete the other uncorrected area,

and paste and replace the copied area.

 


Sorry, not sure what you are talking about.

Maybe it gets clearer what you are looking for if you provide a specific example of what you are trying to achieve.

 

View solution in original post

7 REPLIES 7
Werner_E
24-Ruby V
(To:ssato)


@ssato wrote:

Hello everyone

 

 Please tell me how to use MATHCAD15 to describe a solve block and a block to be calculated

using the result of this solve block as a subroutine or a function and use it repeatedly.

 

Simply turn the solve block into a function depending on the various input variables you'd need by writing

f(in1,in2,...):=Find(out1,out2,....)

at the end of the solve block instead of just

out:=Find(out1,out2,...)

 


 

I have found this answer below, I want to do this.

The thread in the link you provided deals with a different problem as far as I can tell. Here someone asked for how to turn a whole sheet into a function - a feature still not provided by Mathcad.

The suggestion just was to hide the calculation which should have been done in a separate sheet in a collapsed region to make the worksheet look as clean as if the calculation was done somewhere else.

 


With this method, if I modify only a part of the part that I made a subroutine, will it be the following method?

 

(1) Open each area and modify the same corresponding parts

(2) After correcting in one area, copy this area, delete the other uncorrected area,

and paste and replace the copied area.

 


Sorry, not sure what you are talking about.

Maybe it gets clearer what you are looking for if you provide a specific example of what you are trying to achieve.

 

tietjee
14-Alexandrite
(To:ssato)

Programming in Mathcad is more like working with a scripting language.  The program only goes in one direction, unlike Fortran.  I experience in using a subroutine is writing a function and including it in the program.  The solve block can be written as a function.

 

Cheers,

LucMeekes
23-Emerald III
(To:ssato)

Unless your application is really complicated (showing a worksheet of what you are trying to accomplish will allow us to help you better), most such problems can be implemented by using the solve block as a function.

Here's an example:

LM_20190829_SolveBlockFunction.png

You can even use it symbolically:

LM_20190829_SolveBlockFunctions.png

Success!
Luc

Hmm, thats weird!

When I open your sheet in MC15  I see this, different solutions for -3<y<-2:

B.png

Only if I change the guess value from x=0 to x=0.5 OR if I switch the used algorithm from the default Levenberg-Marquart to Conjugate Gradients or to Quasi Newton I see what you show in your picture.

So its not only the symbolics which is different compared to your MC11.

LucMeekes
23-Emerald III
(To:Werner_E)

Mathcad/Maple finds there are 4 possible functions x(y), two are real, two are complex (have a real and imaginary part, they are (of course) complex conjugates. Below are plots from the symbolic solutions.

 

LM_20190829_SolveBlockSolutions.png

Changing the guess value to 0.5 doesn't change the plot in Mathcad 11, but changing it to 1.2 I get the upper solution (as shown by ps1). For a guess of x:=2, my plot also jumps. Given a real guess value, the (numeric) solve block can only find the real solutions. Apparently Mathcad 15's algorithm is more happy to jump between solutions than Mathcad 11.

 

Luc


Apparently Mathcad 15's algorithm is more happy to jump between solutions than Mathcad 11.

At least it behaves differently which was a little surprise to me as I was not aware of any major changes in the implementation of the underlying numeric algorithms.

 

ssato
14-Alexandrite
(To:ssato)

Thanks everyone

 

 My plan uses the result obtained from the first solve block,

constructs a second solve block, finds the result,

and obtains another calculation result.

 

It seems that these can be combined into a single solve block,

but I thought it was difficult to describe them in an easy-to-read,

easy-to-understand manner.

 

For this reason, I thought that the method I showed in the link

would be good if possible.

 

Top Tags