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

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

Vector or matrix from a for loop

MS_12003747
3-Newcomer

Vector or matrix from a for loop

Hello,

I have separated a small for-loop from my calculation. This also works correctly.
Now I would like to save ai for each i or rather access individual values. Furthermore, I would like to draw a graph. y-->ai and x-->i
I would be grateful for any help 🙂
Kind regards
Max

ACCEPTED SOLUTION

Accepted Solutions
StuartBruff
23-Emerald III
(To:MS_12003747)


@MS_12003747 wrote:

Hello,

I have separated a small for-loop from my calculation. This also works correctly.
Now I would like to save ai for each i or rather access individual values. Furthermore, I would like to draw a graph. y-->ai and x-->i


Hi, Max.

 

A solution to the requirement is to add each ai value to a vector in the loop and then return the whole vector. I've added 'comments' to each line that I've modified - note that the return in the last line is necessary, otherwise, Mathcad returns the vector and the comment.

Then simply create a range variable to match the new vector and plot the result.

 

2024 09 23 G.png

 

Stuart

 

Edited to add:

 

I've had an unreliable internet service today and couldn't upload your (modified) worksheet.  However, as the output of the calculation looks almost linear, I guessed that increasing the ai interval by 100 or so, shouldn't have too much effect on the results; it doesn't appear to, only differing by 0.01 from the original value.

 

This allowed me to reduce the size of the worksheet from almost 5 MiB to 294 KiB, which should be (and was) sufficiently short to reliabily upload.

 

View solution in original post

5 REPLIES 5
StuartBruff
23-Emerald III
(To:MS_12003747)


@MS_12003747 wrote:

Hello,

I have separated a small for-loop from my calculation. This also works correctly.
Now I would like to save ai for each i or rather access individual values. Furthermore, I would like to draw a graph. y-->ai and x-->i


Hi, Max.

 

A solution to the requirement is to add each ai value to a vector in the loop and then return the whole vector. I've added 'comments' to each line that I've modified - note that the return in the last line is necessary, otherwise, Mathcad returns the vector and the comment.

Then simply create a range variable to match the new vector and plot the result.

 

2024 09 23 G.png

 

Stuart

 

Edited to add:

 

I've had an unreliable internet service today and couldn't upload your (modified) worksheet.  However, as the output of the calculation looks almost linear, I guessed that increasing the ai interval by 100 or so, shouldn't have too much effect on the results; it doesn't appear to, only differing by 0.01 from the original value.

 

This allowed me to reduce the size of the worksheet from almost 5 MiB to 294 KiB, which should be (and was) sufficiently short to reliabily upload.

 

Really, thank you very much! I now understand the procedure! This helps me a lot!

StuartBruff
23-Emerald III
(To:MS_12003747)

Kein Problem, Max.

 

Stuart

I have just one more question.
Is it also possible to simply save a vector, e.g. for DeltaK from the loop ? The variable is not known outside of the loop.
The loop only gives me a vector for ad.
Thanks and best regards,
Max

 

Sorry,

it was just possible using a matrix!
Thanks anyway!

StuartBruff
23-Emerald III
(To:MS_12003747)

Auch kein Problem, Max. (na ja, jedenfalls nicht für mich!)

 

Freut mich, dass du das geklärt hast

 

Stuart

Announcements

Top Tags