Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X
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.
Solved! Go to Solution.
A quick hack would be to use my "WedgeNew" function in a loop and collect the results column-wise in a matrix:
But its more efficient to rewrite the WedgeNew function to do the job right away:
So when you demand for 20 steps, the results of "disp" and "pres" would be a 11 x 20 matrix each.
Mathcad 15 sheet attached
EDIT: I just noted that you sure can delete this loop
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
used to create matrix K by using the matrix command
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, 😉
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.
Not sure if the animation makes much sense
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:
But its more efficient to rewrite the WedgeNew function to do the job right away:
So when you demand for 20 steps, the results of "disp" and "pres" would be a 11 x 20 matrix each.
Mathcad 15 sheet attached
EDIT: I just noted that you sure can delete this loop
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
used to create matrix K by using the matrix command
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, 😉