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

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

Iterate a function for a range of variables

AhmedAlshawi
1-Newbie

Iterate a function for a range of variables

Hi,

 

I am trying to run an equation in Mathcad 14 but to have it run through a loop from i=1 to i=29. I then want the output to be in an array form with each solution to the equation being output sequentially in the array.

 

e.g. put i=1 into the equation and run, output goes into row 1 of array

put i=2 into the equation and run, output goes into row 2 of array

 

I have attached an image showing my manual method, where I have laboriously gone through and done the equation 29 times (only the first several are shown). The image also shows my attempt at streamlining the equation to iterate through all 29, but this only outputs the answer at i=29 (the last one).

 

Any help would be appreciated.

2 REPLIES 2

Hi,

 

Problem 1.  Arrays start numbering by default at 0.  You can set it to starting at 1 by declaring ORIGIN:-1

 

Problem 2 If you are using a program to define a variable XyyT2 it does not need the index i on the left hand side of the assignment equal sign.

 

Problem 3.  In the program for loop you calculate a value but don't assign it to something.  Here in front of the mathematics you declare the XyyT2i is assigned the value of the calculation.

 

Problem 4.  If you do not specifically return something using the return statement a small program will return the last thing it does.  Outside of the for loop in good programming you need a specific return statement return at this point the XyyT2 vector.

 

If you post the file I will show you.

Please attach your worksheet to clarify your problem.

You may have to zip it first. A serious bug in this forum often prevents from attaching a mathcad file. In Windows Explorer click with the right-mouse button on the mathcad file and select 'Send to' -> 'Compressed (zipped) folder'. The resulting .zip file can be attached

Your sheet can be easily adjusted.  You don't need a program:

Capture.PNG

Top Tags