MATLAB: Define Matrix w/ Values up to y100

  • Thread starter Thread starter henryc09
  • Start date Start date
  • Tags Tags
    Matlab Matrix
Click For Summary
SUMMARY

The discussion focuses on defining a matrix in MATLAB that computes values from y1 to y100 based on a user-defined parameter p and an array dxn. The user seeks a method to automate the generation of these values without manually coding each one. The solution involves utilizing a for loop to iterate through the calculations, storing the results in an array. Specifically, the formula y[i] = 1/(1 + sum(dxn(1:i))) is proposed to efficiently compute the required values.

PREREQUISITES
  • Familiarity with MATLAB programming language
  • Understanding of matrix operations in MATLAB
  • Knowledge of for loops and array indexing
  • Basic concepts of summation and reciprocal calculations
NEXT STEPS
  • Learn about MATLAB array manipulation techniques
  • Explore MATLAB's built-in functions for summation and matrix operations
  • Research advanced MATLAB looping constructs and performance optimization
  • Investigate user input handling in MATLAB for dynamic parameter setting
USEFUL FOR

This discussion is beneficial for MATLAB users, particularly students and professionals involved in numerical analysis, algorithm development, and anyone looking to automate matrix calculations efficiently.

henryc09
Messages
68
Reaction score
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
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.
 
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)))
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 14 ·
Replies
14
Views
4K
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
11K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 10 ·
Replies
10
Views
3K