Creating an Array of X Values for Plotting a Function

This will require you to choose a finite domain that captures the behavior of your function over the range (-\infty,-R).In summary, to create a plot of a given function for all x values between negative infinite to negative R, you can overcome the limitation of Matlab by compactifying the domain of your function to a finite domain and then rescaling the function over the new domain. This will allow you to include all the x values in your plot.
  • #1
airelemental135
13
0
I want to create a plot of a given function for all x values between negative infinite to negative R (for some given R value). How do I create an array for x so that my plot will include all the x values?
 
Physics news on Phys.org
  • #2
airelemental135 said:
I want to create a plot of a given function for all x values between negative infinite to negative R (for some given R value). How do I create an array for x so that my plot will include all the x values?

You can't plot on a range [itex](-\infty,-R)[/itex] since Matlab won't accept Inf or NaN as valid points in the domain of a plot.

Of course, you can overcome this simply by compactifying the domain of your function to a finite domain, and then plotting the rescaled function over the new domain.
 
  • #3


To create an array of x values for plotting a function, you can use a built-in function in your programming language, such as linspace in MATLAB or numpy.linspace in Python. This function allows you to specify the start and end points of the array, as well as the number of values you want in between. In this case, you would set the start point to negative infinity and the end point to negative R, and choose a suitable number of points to include in the array. This will ensure that your plot includes all the x values you need. Additionally, you can also manually create an array of x values by using a for loop or list comprehension in your code.
 

Related to Creating an Array of X Values for Plotting a Function

1. How do I create an array of X values for plotting a function?

To create an array of X values for plotting a function, you can use a variety of methods depending on the programming language you are using. One common approach is to use a for loop to iterate through a range of values and add them to an empty array. Another option is to use built-in functions or libraries specific to your programming language that can generate an array of values for you.

2. What is the purpose of creating an array of X values for plotting a function?

The purpose of creating an array of X values for plotting a function is to provide a set of input values for the function to be evaluated at. These X values will then be used to plot the corresponding Y values on a graph, allowing for a visual representation of the function's behavior and relationship between the input and output values.

3. Can I use any type of values in the array for plotting a function?

Yes, you can use any type of values in the array for plotting a function as long as they are compatible with the function. For example, if your function only takes in integer values, then your array should only contain integer values. It is important to ensure that the values in your array align with the requirements of your function to avoid errors.

4. How many X values do I need for plotting a function?

The number of X values you need for plotting a function depends on the desired level of detail in your graph. Generally, the more values you have, the smoother and more accurate the graph will be. However, having too many values can also lead to clutter and make the graph difficult to read. It is recommended to have a balanced number of values to accurately represent the function without overwhelming the graph.

5. Can I modify the X values in the array after creating it?

Yes, you can modify the X values in the array after creating it. If you need to make changes to the X values, you can simply access and modify the elements in the array using their index. However, keep in mind that any changes made to the X values will also affect the corresponding Y values, so it is important to make sure the modifications align with the intended function behavior.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
667
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
803
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
897
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
Back
Top