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

In summary, to evaluate a function at integer values in MATLAB, you can use a loop within a loop and create a matrix using meshgrid. For the specific function z = x + y, the code would be 'z = x + y;'. To create a matrix with a specific pattern and a vector with a specific form, you can use the code 'A = [2*eye(n) ones(n,n-1); ones(n,n-1) 2*eye(n)]; v = [n-1*ones(n-1,1); n*ones(n,1); n-1*ones(n-1,1)]'. This will create a matrix A and vector v with the desired pattern and form, for
  • #1
jaejoon89
195
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
  • #2
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
 
  • #3
Code:
[x y] = meshgrid(1:1000);
z = x + y;
 
  • #4
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.
 
  • #5


To evaluate a function at integer values of x and y in MATLAB, you can use the "meshgrid" function to create a grid of x and y values ranging from 1 to 1000. Then, you can use the "eval" function to evaluate the function at each point on the grid and store the results in a matrix. In this case, the code would look something like this:

[x,y] = meshgrid(1:1000, 1:1000); % create a grid of x and y values
z = eval('x + y'); % evaluate the function at each point on the grid and store the results in a matrix
plot3(x,y,z); % plot the results in 3D to visualize the function's surface
 

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

1. What is the purpose of evaluating functions in MATLAB with an x,y range of 1-1000?

The purpose of evaluating functions in MATLAB with an x,y range of 1-1000 is to analyze the behavior of a function over a large range of input values. This can provide valuable insights and help in making decisions related to the function's use and optimization.

2. How do I specify the x,y range when evaluating a function in MATLAB?

To specify the x,y range when evaluating a function in MATLAB, you can use the colon operator ":". For example, if you want to evaluate the function for x values from 1 to 1000, you can use the syntax "x = 1:1000". This will create a vector with values from 1 to 1000 that can be used as input for the function.

3. Can I evaluate multiple functions at once with an x,y range of 1-1000 in MATLAB?

Yes, you can evaluate multiple functions at once with an x,y range of 1-1000 in MATLAB by using the element-wise operations. This allows you to perform operations on arrays of values, making it possible to evaluate multiple functions simultaneously.

4. How can I plot the results of evaluating a function in MATLAB with an x,y range of 1-1000?

To plot the results of evaluating a function in MATLAB with an x,y range of 1-1000, you can use the "plot" function. This will generate a line plot with the x values on the horizontal axis and the corresponding y values on the vertical axis. You can also customize the plot by adding labels, titles, and adjusting the axes.

5. Is it possible to evaluate functions with non-numeric inputs in MATLAB?

Yes, it is possible to evaluate functions with non-numeric inputs in MATLAB. This can be done by using symbolic variables and functions, which allow you to work with algebraic expressions and perform operations on them. This can be useful for evaluating functions that involve symbols or variables instead of fixed numbers.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
845
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
Back
Top