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

The community will undergo maintenance on October 16th at 10:00 PM PDT and will be unavailable for up to one hour.

Following/Develop a Matrix Through Nested Loops

hw
1-Newbie
1-Newbie

Following/Develop a Matrix Through Nested Loops

Greetings, I am trying to go back and forth between two loops that utilize two different solver functions, each of which, develop a matrix. My goal is to keep track of the data in one main matrix that is developed in each loop while also using the data from the final iteration of previous loop to act as the initial values in the new loop as it begins the next set of iterations. My first question I guess is, is this possible? Of course there are more details to it, for instance; 1) Each loop is entered and exited based on conditional statements 2) I want to also keep a counter that controls all loops, so once the counter is has reached a limit the main Matrix is completed, and output I attached an attempt at this problem, however I think my conditional statements may hinder the overall function of the problem. So if there is a simple example that can illustrate how to follow/develop a Matrix to and from a nested loop, I think that could be most helpful as well. Many Thanks, HW
5 REPLIES 5
RichardJ
19-Tanzanite
(To:hw)

I'm sure that what you want to do is possible, but it's not clear to me what you want to do. You talk about going backward and forward between two loops, but also about nested loops. If they are nested you can't go backward and forward between them. Could you write out the sequence of what you want to happen. For example: Solve Function1 to get the parameters Start loop If some condition Use the parameters as input to Function2 Solve to get new parameters If some condition Use the parameters as input to Function1 Solve to get new parameters End Loop repeat the loop until some condition is met? Or are you just trying to loop through the values of Ks? Apart from not understanding what you want to do with the loop, there is a more serious problem. Your solve blocks have only 5 equations but you are trying to find 7 unknowns. The number of equations must match the number of unknowns. Richard
hw
1-Newbie
1-Newbie
(To:RichardJ)

Richard, First thanks for replying, I was hoping you would respond. I will try to better explain what I am attempting to do, but let me address a couple of things. 1) It is good to know that you can not go back and forth between a NESTED loop and a main loop, it is a path I have been trying to go down for a while(no pun intended) with no success. I will make the loops parallel. 2) As far as the equations matching the unknowns, while it may not be very clear, I do only have 5 unknowns for each function as for function #1 lambda is const and “a� is just a counter, and function #2 mlt is const, and again “a� is the counter. “a� is included in the solver function to load the matrix vector as each iteration is carried out, there is probably another way to do this but this seemed to be the easiest way. Loop Description: What you typed is essentially what I am trying to do. Although I would add that the values of K1 through K5 and lambda all need to be “recorded� in a matrix as it goes back and forth between Function1 and 2. Example: When Function1 is done solving, given a set of conditions, x number of vectors that are input into Matrix1, the last vector calculated acts as the initial vector to Function2 but ALSO all those values from the Function1 iteration are recorded in the same matrix as all the vectors calculated with Function2. The final output will be a matrix that has values that are a combo of values from function1 and 2. For instance “a� represents the counter and vector(each vector is the 7 values I want to see as in work sheet) position in the matrix, so say for “a� 1-250 you have Function1 values and for “a� 251-389 you have function2 values, then 390-520 function1, 521-590 function2, so on and so forth until counter reaches limit. Your questions: repeat the loop until some condition is met? Yes until the counter is finished: “a� reaches say 1440 Or are you just trying to loop through the values of Ks? No, Ks could be constant, but it is just a variable I control to manipulate the behavior of the solver functions. The number of Ks is definitely related to the total number of iterations I want the two Functions to go through, but is not controlling the loop start and stop. Does all this make sense? I can try to clarify more, and again any help is appreciated. Best, HW
hw
1-Newbie
1-Newbie
(To:hw)

I found a variable error in the previous attachment this new attachment is a correction. I also put the loops on the same level but still not getting Matrix that combines both functions. So again any help would be appreciated. Best, HW
RichardJ
19-Tanzanite
(To:hw)

"Hogan Winn" wrote:

2) As far as the equations matching the unknowns, while it may not be very clear, I do only have 5 unknowns for each function as for function #1 lambda is const and “a� is just a counter, and function #2 mlt is const, and again “a� is the counter. “a� is included in the solver function to load the matrix vector as each iteration is carried out, there is probably another way to do this but this seemed to be the easiest way.

hw
1-Newbie
1-Newbie
(To:RichardJ)

Richard thanks your simplification of the loop and conditional statements, much more eloquent. I apologize for the confusion, my conditional statements are weak, and I thought I could ask the question without fully realizing them. This probably made the point that l3 is constant in solve block 1 and K3 is variable, but in solve block 2 K3 becomes constant and l3 is variable, hard to understand. My conditional statements may still not be solid but, the question now is can I get the initial vector values with function 1 OUTSIDE the FOR loop. I just want to get those values once and then not use that function again without a conditional statement assigned to it, which is inside the FOR loop. I am trying to debug and I don't want this to influence results. I tried taking this initial evaluation out of the FOR loop but then I have issues with an invalid array index. Suggestions? I attached a rework that gets me in the function 1 then to the function 2, however it is still not behaving correctly. Namely l3 should approach 1 as function 2 is utilized, and when 1 is reached, the loop should toggle over to function 1. (the loop funct2test shows how funct2 works) So here is a summary of the logic I think can work: 1) Set initial vector with solve block function 1 calc FOR a set number of iterations 2) If l3b equal to 0 OR l3b equal to 1 Then calc solve block function 1 3) If K3b is greater or equal to mlt AND l3b is between 0 and 1, where l3b can equal 0 but less than 1 (if changed to less than and equal to 1 can see example how funct 1 goes to funct 2) Then calc solve block function 2 4) End Loop 5) Output cumulative Matrix. Thanks again, and let me know if this is still confusing. I think the attachment helps explain what I am trying to do. Also, on a side note, you seem to be very knowledgeable about MathCAD, would you have any suggestions as to where I could get some serious MathCAD training? Best Hogan
Announcements

Top Tags