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

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

Translate the entire conversation x

FOR and IF cycles in iterative solving of two equations by values substituting

Ivan_Pat
12-Amethyst

FOR and IF cycles in iterative solving of two equations by values substituting

Dear PTC Mathcad Community,

I am working in Mathcad Prime on a nonlinear moment–curvature analysis of a reinforced concrete section according to Ukrainian concrete Code ДСТУ Б В.2.6-156:2010 (Appendix A, second equilibrium form).

I implemented a step-by-step algorithm with nested FOR loops, conditional checks, and accumulation of results into a matrix Moment_curvature.

Problem description

I expect to obtain a matrix with multiple rows (i.e., 10 rows), where each row corresponds to the final iteration of strains (εc1, εc2), which have to iterate until the condition of equation (4.3) N<0 is true, and contains:

  • iteration index
  • concrete strains εc1, εc2
  • curvature א
  • steel stresses
  • bending moment M

However, Mathcad returns an empty table only, even though:

  • the outer loop is defined as for i ∈ 1..n with n = 20
  • the loop body is executed
  • no errors are reported

I understand that my script is one of the few possible ways to solve the issue; thus, with this regard, my questions arose:

  • How can I use a WHILE loop for my iteration until the condition of equation (4.3), N<0, is true, in the correct way to substitute the found value of εc2, which led to the condition of equation (4.3), N<0, in Mathcad Prime (if it is a more straightforward way to mess with)?
  • What are my mistakes that lead to Mathcad returning only the empty expression of a 20x9 matrix instead of the full loop result?

I would greatly appreciate any guidance, examples, or references on best practices for iterative algorithms and matrix construction in Mathcad Prime that could help me resolve the issue.

Thank you very much for your time and support.

 

P.S.

For clarity, I attach my zipped file, which describes the algorithm I wish to realise in Prime 10.0.0 version.

Also, the explanation of what I expect to get from the code, the picture of the curvature, and the Table of data (performed in an online software) have been added to the attached Mathcad file.

8 REPLIES 8
LucMeekes
23-Emerald IV
(To:Ivan_Pat)

Hi Ivan,

Your file was not attached.

It seems there is a problem with attaching files on the forum presently.

What appears to work is if you ZIP the Prime 10 .MCDX file and attach that .ZIP file.

   To ZIP the file, in Windows Explorer select the file and then from the right-mouse-click menu choose 

   Send To => Compressed (zipped) folder

 

Success!
Luc

 

Ivan_Pat
12-Amethyst
(To:LucMeekes)

@LucMeekes Thank you for the comment. I'll try to fix the issue with the attachment.

LucMeekes
23-Emerald IV
(To:Ivan_Pat)

That worked.

Now to your algorithm:

You have the assignments to Moment_curvature[i,1  through [i,9 outside of the for loop that iterates over i. So at that point i is a constant. Only the last row of the Moment_curvature matrix gets filled. See here:

LucMeekes_0-1765716277719.png

I guess you must move the assignments upwards in the algorithm, probably at the end of the For loop.

 

Success!
Luc

 

 

 

Ivan_Pat
12-Amethyst
(To:LucMeekes)

@LucMeekes Thanks for the quick reply. I'll look through the routine, but the question is: whether the assignment should be moved into the FOR loop (where i decrements), and how to "explain" to the code that I need to go further through all the epsilon_c1 increments.

Ivan_Pat_0-1765728447857.png

 

As you see, it is better than the previous look, but all the data is fixed without incrementing.

 

LucMeekes
23-Emerald IV
(To:Ivan_Pat)

I only have limited time to look at your sheet, and absolutely no idea what it is about. Just trying  to spot common errors.

You state further down the sheet that you expect a 10-line matrix.

Your index i runs over 20, but you have another for loop where m runs up to 10.

Maybe you need to store the data from within that for loop, using m instead of i...?

 

There should be no need to assign a variable to itself. So all the 

LucMeekes_0-1765723964980.pngLucMeekes_1-1765723984436.pngLucMeekes_2-1765724007317.png

and the like can be omitted. 

Note that the result of the function is the (result of the ) last assignment. It is good habit to exit the function with a 

    return Moment_curvature

at a(ny) suitable spot. Your error detection(s) could be changed to 

    return "Something went wrong X" 

in which case the program will stop and produce that string as result.

 

Success!
Luc

 

 

Ivan_Pat
12-Amethyst
(To:LucMeekes)

@LucMeekes  Thank you a lot for your noticeable remarks regarding the:


@LucMeekes wrote:

...

You state further down the sheet that you expect a 10-line matrix.

Your index i runs over 20, but you have another for loop where m runs up to 10.

Maybe you need to store the data from within that for loop, using m instead of i...?

 

There should be no need to assign a variable to itself. So all the 

LucMeekes_0-1765723964980.pngLucMeekes_1-1765723984436.pngLucMeekes_2-1765724007317.png

and the like can be omitted. 

Note that the result of the function is the (result of the ) last assignment. It is good habit to exit the function with a 

    return Moment_curvature

at a(ny) suitable spot. Your error detection(s) could be changed to 

    return "Something went wrong X" 

in which case the program will stop and produce that string as result.

...


I have even thought about my issue: to do a nested FOR loop, where the i-th iteration increments the epsilon c2 variable (slave) and the second FOR loop iterates over the m-th iteration of the epsilon c1 (master).

Nevertheless, I'll try to fix it, as I understand.🙂

 

 

Ivan_Pat
12-Amethyst
(To:Ivan_Pat)

@LucMeekes  I have fixed the proposed remarks... and  now I can see the error place

Ivan_Pat_0-1765806805585.png

But it still doesn't work as it should.

LucMeekes
23-Emerald IV
(To:Ivan_Pat)

If you change:

    return "Something went wrong 2!"

with

    return [ "error 2" Nnew Nnewest epsilonc2new epsilonc2old tolerance ]

you will get the values of the variables that are involved in the IF statement and can decide what made the test fail.

Note that [    ] is a 1-row matrix.

 

Success!
Luc

Announcements

Top Tags