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

Community email notifications are disrupted. While we are working to resolve, please check on your favorite boards regularly to keep up with your conversations and new topics.

Can I Use a for or while here ?

drgriffin
1-Newbie

Can I Use a for or while here ?

The attached file works fine. However if I try to use a for or while loop I get a horizontal line. Is there a way to incorporate these statements in a loop ?
6 REPLIES 6
RichardJ
19-Tanzanite
(To:drgriffin)

Incorporate them in a loop to do what? Could you post a sheet showing what you are trying to do with the loop.

Richard
StuartBruff
23-Emerald II
(To:drgriffin)

On 12/6/2009 11:27:48 AM, dmg wrote:
>> The attached file works fine. However if I try
to use a for or while loop I get a horizontal line.
Is there a way to incorporate these statements in a
loop ?

As Richard says, without seeing what you've done in
the loop, it's difficult to say what your problem
is.

However, is the attached of any use?

Stuart

You program took my output and used a loop to reproduce my plot. I want a single program that starts with mine and outputs the plot data.

BTW - thanks for the help
RichardJ
19-Tanzanite
(To:drgriffin)

Is this what you want?

If not, please post a worksheet showing what you are trying to do. Then we don't have to play guessing games.

Richard

Yes, I suppose it is - I think the problem is the nature of "programming" using Mathcad constructs vs say fortran or C++. In Mathcad a "program" can consist of a number of smaller programmed elements in the same file, as is the case here. I was originally thinking along the lines of how it would be done in a single program in, say fortran. This approach is better I think.
RichardJ
19-Tanzanite
(To:drgriffin)

On 12/6/2009 4:34:16 PM, dmg wrote:
>Yes, I suppose it is - I think
>the problem is the nature of
>"programming" using Mathcad
>constructs vs say fortran or
>C++.

Yes, it's a very different environment.

>In Mathcad a "program"

We refer to it as a worksheet.

>can consist of a number of
>smaller programmed elements in
>the same file, as is the case
>here.

You can enter expressions in a worksheet much the same way as you would write them on paper. Execution order is top left to bottom right, just as you would read a page. Just as in Fortran or C++ you can create a function that can be called later in the worksheet, or you can just evaluate an expression and assign the result (which is not restricted to being a scalar value) to a variable. You also have ways to create conditional statements and "loops" in the worksheet. For conditional statements you have the "if" function. For "loops", you have range variables. Note that a range variable is an iterator, just like a loop variable in Fortran or C, it is not a vector of values. This seems to confuse a lot of people. If I write

i:0;10
x[i:i/10

then the latter expression is evaluated for each value of i, which means x becomes a vector of values.

Sometimes it's difficult or impossible to do what you want just by typing one line statements in the worksheet though, in which case Mathcad has what are termed "programs". Just like a single line statement, a program can either assign a value to a variable, or it could define a function.

>I was originally
>thinking along the lines of
>how it would be done in a
>single program in, say
>fortran.

Confusing terminology!

>This approach is
>better I think.

Well, we all think so 🙂

Richard
Top Tags