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

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

Indexing for Advance in Time

JohnRudnicki
15-Moonstone

Indexing for Advance in Time

I have a program that I have written for a fixed time step and then advanced it for two, but obviously I want to do this for many. I thought I could just do this with a for loop but I have various matrix operations in the program and cannot get the indexing right. Do I need to convert everything to indicies? There must be a simpler, more elegant and efficient way.

 

The program is highlighted and annotated at the bottom of the worksheet. There are some auxiliary programs at the top. I am using MathCad 14. (BTW I do have a reason for setting the ORIGIN to -N, but I do not think this is relevant).

 

Thanks in advance for any help.

ACCEPTED SOLUTION

Accepted Solutions

A quick hack would be to use my "WedgeNew" function in a loop and collect the results column-wise in a matrix:

Werner_E_0-1713361387086.png

But its more efficient to rewrite the WedgeNew function to do the job right away:

Werner_E_1-1713361433959.png

 

So when you demand for 20 steps, the results of "disp" and "pres" would be a 11 x 20 matrix each.

Werner_E_2-1713361598269.png

 

Mathcad 15 sheet attached

 

 

EDIT: I just noted that you sure can delete this loop

Werner_E_3-1713362551942.png

in the various "Wedge" functions as is has no effect. Y is never used later and Y would be identical to X anyway.

 

While I am at it - you can replace the nested loops

Werner_E_4-1713363280884.png

used to create matrix K by using the matrix command

Werner_E_5-1713363298821.png

But when I now compare the two, I guess the second isn't much easier or shorter and the nested loops may show clearer which calculation is applied, 😉

View solution in original post

3 REPLIES 3

It looks to me that you are only interested in the results of the last iteration step, right?

So it would not be necessary to store all the intermediate results in a matrix.

Here is what I came up with - hope it helps.

Werner_E_0-1713290624397.png

Werner_E_1-1713290887078.png

 

Not sure if the animation makes much sense

Ani1.gif

Worksheet and avi attached

 

Hi Werner,

 

Thanks. The animation does make perfect sense! Although it was not clear from the worksheet I posted I do want to store the values from all the steps. When I get all done, I want to plot certain features of the calculation as a function of time. I wanted to store, e.g. the values of u in a matrix with each column being the results at an individual time step. This what I could not figure out how to index.

 

John

A quick hack would be to use my "WedgeNew" function in a loop and collect the results column-wise in a matrix:

Werner_E_0-1713361387086.png

But its more efficient to rewrite the WedgeNew function to do the job right away:

Werner_E_1-1713361433959.png

 

So when you demand for 20 steps, the results of "disp" and "pres" would be a 11 x 20 matrix each.

Werner_E_2-1713361598269.png

 

Mathcad 15 sheet attached

 

 

EDIT: I just noted that you sure can delete this loop

Werner_E_3-1713362551942.png

in the various "Wedge" functions as is has no effect. Y is never used later and Y would be identical to X anyway.

 

While I am at it - you can replace the nested loops

Werner_E_4-1713363280884.png

used to create matrix K by using the matrix command

Werner_E_5-1713363298821.png

But when I now compare the two, I guess the second isn't much easier or shorter and the nested loops may show clearer which calculation is applied, 😉

Announcements

Top Tags