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

Why Doesn't this Loop work?

JohnRudnicki
14-Alexandrite

Why Doesn't this Loop work?

I thought I was making an innocuous change in a program, but it causes the For loop (or maybe the Solve block call) to fail. I haven't been able to figure out what the problem is. Worksheet is attached - program is shown at the bottom. Thanks in advance for any help.

1 ACCEPTED SOLUTION

Accepted Solutions

And finally a version which also gets rid of the initial extra call to FuncTry in front of the loop. Instead of "augment" the column selector is now used to create the matrix "Out".

Werner_E_4-1661853562249.png

As you can see, I also rename "tauGuess" and "phiGuess" to just "tau" and "phi", but thats only cosmetics (but it makes the program look even smaller 😉

 

Worksheet saved in MC11 format attached

 

 

 

View solution in original post

5 REPLIES 5

You are talking about the difference in behaviour between function "Solve2" and "Solve3" and the solve block "FuncTry" failing when called in "Solve3" ??
I guess that this solve block and the functions used therein assume that S is a scalar, right? (I have not digged in the details so far)

But in "Solve3" S is turned into a vector of values and this seems to throws the error.

Can it be that you inadvertently used the name "S" for two different things in your program?
Furthermore, you have ORIGIN=0 but you start the vectors S, x, v, Out and others with index 1. It looks to me that most of this vectors are not necessary to be vectors as you don't use the previous value in the next iteration.

LucMeekes
23-Emerald III
(To:JohnRudnicki)

Hi John,

@Werner_E has sharp eyes.

Here is a corrected version, with the corrections marked.

 

Success!
Luc

@LucMeekes  changed the variable name of the vector S in your program to Ss to avoid the aforementioned conflict with the function argument S.

Here is a streamlined version of your program which gets completely rid of this variable Ss (also of v) and also avoids the creation of those unnecessary vectors (as outlined in my first reply.
Its also not necessary to collect all those previous "Outs" in a vector as every "Out" contains the values of the "Outs" before with just one column added.

IMHO this "vectorless" version looks a bit more cleaner 😉

Werner_E_0-1661852212285.png

And here is another modification which also gets rid of the local variable "R":

Werner_E_2-1661853475224.png

And finally a version which also gets rid of the initial extra call to FuncTry in front of the loop. Instead of "augment" the column selector is now used to create the matrix "Out".

Werner_E_4-1661853562249.png

As you can see, I also rename "tauGuess" and "phiGuess" to just "tau" and "phi", but thats only cosmetics (but it makes the program look even smaller 😉

 

Worksheet saved in MC11 format attached

 

 

 

JohnRudnicki
14-Alexandrite
(To:Werner_E)

Thanks. Your first message made me realize what the problem was. But thanks for cleaning and streamlining my program. As you probably know by now, despite using MC for many years, I am still a utilitarian programmer!

Top Tags