Evaluating Functions in MATLAB with x,y Range 1-1000

Click For Summary
SUMMARY

This discussion focuses on evaluating functions in MATLAB for integer values of x and y ranging from 1 to 1000, specifically using the function z = x + y. The recommended approach involves utilizing nested loops or the meshgrid function for efficient computation. A sample code snippet demonstrates the creation of a 1000x1000 matrix z initialized with zeros, followed by the application of loops to populate it. Additionally, the discussion includes a request for generating a specific matrix pattern and a vector of a defined structure.

PREREQUISITES
  • Familiarity with MATLAB programming language
  • Understanding of matrix operations in MATLAB
  • Knowledge of loops and vectorization techniques
  • Experience with the meshgrid function in MATLAB
NEXT STEPS
  • Explore MATLAB's vectorization techniques for performance optimization
  • Learn how to create custom matrices using MATLAB functions
  • Investigate the use of the meshgrid function for multidimensional data
  • Study advanced MATLAB indexing and manipulation of matrices
USEFUL FOR

This discussion is beneficial for MATLAB users, data analysts, and engineers who need to evaluate mathematical functions over a range of values and create specific matrix patterns for computational tasks.

jaejoon89
Messages
187
Reaction score
0
Using MATLAB, how do you evaluate a function at integer values, say 1 to 1000, of x and y? For simplicity, let's say the function is z = x + y.
 
Physics news on Phys.org
Hello

Try a loop within a loop to go through all x values then all y values?

Code:
z = zeros(1000);
for x= 1:1000
    for y = 1:1000
        z(x,y) = x + y;
    end
end
 
Code:
[x y] = meshgrid(1:1000);
z = x + y;
 
Hi
Can anyone help how to write the matrix
A=[ 2 1 0 0 0
0 2 1 0 0
1 0 2 1 0
0 1 0 2 1
0 0 1 0 2]
I need A with the above pattern of any dimension n and also a vector of the form
v=[3 3 4 4 4 4 ...4 3 3]^T where v can be of any dimension. I'll be grateful for your help.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
Replies
5
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K