Use results of a 'for' loop to formulate a vector

  • Thread starter Thread starter timsea81
  • Start date Start date
  • Tags Tags
    Loop Vector
Click For Summary

Discussion Overview

The discussion revolves around how to use a 'for' loop to generate and store results in a vector for plotting purposes. It includes considerations of different programming languages and their handling of vectors and plotting functionalities.

Discussion Character

  • Technical explanation, Homework-related

Main Points Raised

  • One participant seeks to understand how to store results from a 'for' loop as a vector for plotting, providing a simplified example in code.
  • Another participant notes that the approach may vary depending on the programming language used, highlighting differences in vector handling and graphing options.
  • A later reply indicates that the participant has figured out how to create vectors and plot them, mentioning specific calculations and plotting two vectors in different colors.
  • Some participants share a link to a tutorial for a simple explanation of using 'for' loops and vectors in Matlab.

Areas of Agreement / Disagreement

Participants express varying levels of understanding and approaches to the problem, with no consensus on a single method due to the differences in programming languages mentioned.

Contextual Notes

The discussion does not resolve specific programming language syntax or the details of plotting multiple vectors, leaving those aspects open for further exploration.

timsea81
Messages
89
Reaction score
1
I would think this should be an easy one...

For i=0 to i=M, I want to run a a calculation and get M different results. I want to store those M results as a vector so I can plot them.

Simplify version below:

for i=0:10
T = i/2;
T
end

This spits out a list of numbers: 0, 0.5, 1... How do I store that list as a vector and plot it?
 
Physics news on Phys.org
It depends what language you are using as there's differences between them and how they handle vectors and what graphing options they have.
 
trollcast said:
It depends what language you are using as there's differences between them and how they handle vectors and what graphing options they have.

I think I got it now:

T1 = [1:5];
for i=1:5,
T1(i) = i^6;
T2(i) = i^.01;
plot (T1)
end

Now I just need to figure out how to plot two vectors on top of each other in different colors, but I think I should be able to get that part from the help. Thanks for the response.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 29 ·
Replies
29
Views
5K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 2 ·
Replies
2
Views
1K