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

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

Iteration with an initial value

Ycarlos
14-Alexandrite

Iteration with an initial value

Good morning community. I am trying to program to find a number α so that it meets a condition Psol=0.00 tonnef. In short, what I want is to enter an initial value α and until that condition Psol=0.00 tonnef is met, look for the value of α. Thank you for your attention, my version of Mathcad prime is V.9.0.

 

Translated by the moderation using Google Translate
-----------------------------------------------------------------------------------------------

Iteración con un valor inicial

 

Buen día comunidad. Estoy tratando de programar para buscar un número α para que cumpla una condición Psol=0.00 tonnef.  en resumen, lo que quiero es introducir un valor inicial α y hasta que no se cumpla esa condición Psol=0.00 tonnef busque el valor de α. Gracias por la atención prestada mi versión de Mathcad prime es V.9.0.

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:Ycarlos)

You define a variable alpha at the top and then carry out a series of calculations (mostly using the value of alpha or values ​​derived from it) to calculate a value P.sol at the end.
 
Now you want to vary alpha in such a way as to obtain a specific value (zero) for P.sol.
 
It would be nice if you could turn the whole worksheet into a function with argument alpha.
Being able to do something like this is a very long-held wish, previously in Mathcad and now in Prime.
Unfortunately, this wish has not been fulfilled so far.
 
Therefore, you can only resort to more complicated and complex solutions.
One possibility is to rewrite all calculations that depend on alpha in some way as a function of alpha.
At the end you then have a function P.sol(alpha), the zero of which you can then search for either with the "root" function or with a solution block with "find".
Werner_E_1-1725276050841.png

There is a discrepancy concerning your desired value for M.sol.

You can solve for alpha to get that value for M.sol, but then P.sol is farther away from zero:

Werner_E_2-1725276412276.png

 

Werner_E_4-1725276869432.png

From the plot it looks like your calculations fail for some intermediate values (the red curve should not look dashed otherwise) - have not investigated any further, though.

 

 
Another approach could be to pack all the calculations into a single function P.sol(alpha). This is, given the worksheet already is provided for one run, a much greater effort, I suspect.
 
Worksheet for Prime 9 attached
 

View solution in original post

4 REPLIES 4

Hi,

you cannot compare real number with fixed number (i.e. with zero).

 

Define an interval of small values, i.e. < -epsilon, +epsilon > and compare Psol value with the boundaries of this interval. If the value of Psol is inside the interval, it will mean that it is "equal to zero".


Martin Hanák
Ycarlos
14-Alexandrite
(To:MartinHanak)

Disculpe estimado  Martin Hanak, estuve intentando programar para que me cumpla la condición pero me sale un error, por favor si me lo pueda revisar la parte de color amarillo. Gracias anticipadamente. mathcad V.9

 


@Ycarlos wrote:

Disculpe estimado  Martin Hanak, estuve intentando programar para que me cumpla la condición pero me sale un error, por favor si me lo pueda revisar la parte de color amarillo. Gracias anticipadamente. mathcad V.9

 

Hi,

I am sorry, I absolutely do not understand your yellow calculation. It seems awfully complicated to me and probably full of bugs.

Suggestion: Start with a simple calculation and gradually add more parts. It must be clear to you what value is the result of the calculation or subcalculation.


Martin Hanák
Werner_E
25-Diamond I
(To:Ycarlos)

You define a variable alpha at the top and then carry out a series of calculations (mostly using the value of alpha or values ​​derived from it) to calculate a value P.sol at the end.
 
Now you want to vary alpha in such a way as to obtain a specific value (zero) for P.sol.
 
It would be nice if you could turn the whole worksheet into a function with argument alpha.
Being able to do something like this is a very long-held wish, previously in Mathcad and now in Prime.
Unfortunately, this wish has not been fulfilled so far.
 
Therefore, you can only resort to more complicated and complex solutions.
One possibility is to rewrite all calculations that depend on alpha in some way as a function of alpha.
At the end you then have a function P.sol(alpha), the zero of which you can then search for either with the "root" function or with a solution block with "find".
Werner_E_1-1725276050841.png

There is a discrepancy concerning your desired value for M.sol.

You can solve for alpha to get that value for M.sol, but then P.sol is farther away from zero:

Werner_E_2-1725276412276.png

 

Werner_E_4-1725276869432.png

From the plot it looks like your calculations fail for some intermediate values (the red curve should not look dashed otherwise) - have not investigated any further, though.

 

 
Another approach could be to pack all the calculations into a single function P.sol(alpha). This is, given the worksheet already is provided for one run, a much greater effort, I suspect.
 
Worksheet for Prime 9 attached
 
Announcements

Top Tags