MATLAB: Define Matrix w/ Values up to y100

In summary, the conversation discusses defining variables and arrays for a function and finding a way to calculate and store 100 values without having to define each one individually. The suggested solution involves using a for loop and an empty 100-element array to store the values.
  • #1
henryc09
72
0

Homework Statement


OK, so I have defined:

n=[0:1:100];
p=1.01; (but later will make this so it is inputted by user as a function)
dx1=100*(p-1)/(p^101-1);
dxn=p.^n*dx1;

I need to define y1-y100 like:
y0=1
y1=1/(1+dxn(1))
y2=1/(1+sum(dxn(1:2)))
y3=1/(1+sum(dxn(1:3))) etc

is there some way I can make this into some matrix with values up to y100 without having to write out and define each one individually? Maybe I'm being stupid but I can't see an easy way to do this. Any help would be much appreciated.
 
Physics news on Phys.org
  • #2
I would use an intermediate array variable with 100 elements, and would store the values 1 + dxn(1), 1 + sum(dxn(1:2)), 1 + sum(dxn(1:3), etc. in it, up to 1 + sum(dxn(1:100). If you know about DO loops, you can do this very easily.

After you have calculated all 100 values, store their reciprocals in y1, y2, ... , y100.
 
  • #3
henryc09 said:
is there some way I can make this into some matrix with values up to y100 without having to write out and define each one individually?

for loop and empty 100 element long array?
y=1/(1+sum(dxn(1:i)))
 

1. What is MATLAB?

MATLAB is a programming language and interactive environment designed for scientific computing. It allows scientists and engineers to analyze and visualize data, build algorithms, and create models and applications.

2. How do I define a matrix in MATLAB?

To define a matrix in MATLAB, you can use the "zeros" or "ones" function to create a matrix filled with zeros or ones, respectively. You can also use the "eye" function to create an identity matrix, or the "rand" function to create a matrix filled with random numbers. Additionally, you can manually input values into a matrix using square brackets.

3. What does "values up to 100" mean when defining a matrix in MATLAB?

"Values up to 100" means that the elements in the matrix will range from 1 to 100. For example, if the matrix is 3x3, the values in the matrix will range from 1 to 9.

4. How do I specify the size of a matrix in MATLAB?

To specify the size of a matrix in MATLAB, you can use the syntax "matrixName = zeros(rows, columns)" or "matrixName = ones(rows, columns)" to create a matrix with the specified number of rows and columns. Alternatively, you can use the "size" function to display the dimensions of an existing matrix.

5. Can I define a matrix with non-integer values in MATLAB?

Yes, you can define a matrix with non-integer values in MATLAB. You can use decimal numbers, fractions, or even complex numbers in a matrix. However, keep in mind that MATLAB is primarily used for numerical computations, so non-numeric elements may not be compatible with certain functions.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
892
  • Engineering and Comp Sci Homework Help
Replies
2
Views
831
  • Engineering and Comp Sci Homework Help
Replies
14
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
972
  • Engineering and Comp Sci Homework Help
Replies
4
Views
10K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
835
  • Engineering and Comp Sci Homework Help
Replies
6
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
Back
Top