2D plot of a function WITH MATLAB

In summary, the conversation discusses the function y(x,s) and its variable ranges. The speaker is looking for a way to change the value of s for different values of x, using a for loop. They also mention encountering errors while defining the function. The conversation suggests using the function plot() to generate multiple plots with varying s values. Some suggestions are given for resolving the errors, such as using atan instead of arctan and using the power() function for x^s powers.
  • #1
aredy29
10
0
My function is;

y(x,s)= 1-(cos[(s-1)arctan(x)]*gamma(s-1))/(1+x^2)^(s-1)/2

varible x will have range from 0 to 10. At one time the s value will be constant e.g. s = 3 but I want to change s for different values( is there any commands in MATLAB that will allow me to do this ?). I tried many time but can't get it.
 
Physics news on Phys.org
  • #3
still not clear..
 
  • #4
The idea is to construct a loop to generate the s values say from 0 to 5:

for s = 1:5
x=0:10
y=s*x.*x
plot(x,y)
hold all
end
 
  • #5
how should I define my function ? I keep getting 'm power error'
 
  • #6
Here's an example I did in Freemat, a MATLAB clone, as I don't use MATLAB much anymore

for i = 1:5
s=i
x=0:10
y=s*x
plot(x,y)
hold('on')
end

It draws five plots on one chart with varying s values.
 
  • #7
for your eqn arctan should be atan and for x^s powers you could use power(x,s)

alternatively x^2 = x.*x dots x to x to get a vector of x^2 values
 

What is a 2D plot of a function?

A 2D plot of a function is a graphical representation of a mathematical function on a two-dimensional coordinate system. It shows the relationship between the independent variable (x-axis) and the dependent variable (y-axis).

How can I create a 2D plot of a function with MATLAB?

To create a 2D plot of a function with MATLAB, you can use the "plot" function. This function takes in the x and y values of the function and plots them on a graph. You can also customize the plot by adding a title, labels, and changing the color and style of the line.

What are the benefits of using MATLAB to plot a 2D function?

MATLAB is a powerful tool for creating 2D plots of functions because it has built-in functions for common mathematical operations and has a user-friendly interface. It also allows for easy manipulation and customization of the plot, making it a convenient tool for data analysis and visualization.

Can I plot multiple functions on the same 2D plot with MATLAB?

Yes, you can plot multiple functions on the same 2D plot with MATLAB. You can use the "hold on" function to add additional plots to an existing graph. This allows for easy comparison and analysis of multiple functions.

Is it possible to save a 2D plot of a function in MATLAB?

Yes, you can save a 2D plot of a function in MATLAB by using the "saveas" function. This allows you to save the plot in various file formats such as PNG, JPEG, and PDF. You can also use the "print" function to directly print the plot from MATLAB.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
995
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
745
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
895
  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
Back
Top