MATLAB 2D plot of a function WITH MATLAB

AI Thread Summary
The discussion revolves around plotting a function in MATLAB with varying parameters, specifically for the equation y(x,s) = 1 - (cos[(s-1)arctan(x)]*gamma(s-1))/(1+x^2)^(s-1)/2. Users seek guidance on how to implement a loop that allows for the variable 's' to change while plotting the function over a range of 'x' values from 0 to 10. Suggestions include using the 'atan' function instead of 'arctan' and employing the power operator correctly for vectorized operations. The example provided demonstrates how to plot multiple lines on a single chart by iterating through values of 's'. Proper function definition and vector operations are crucial for avoiding errors in MATLAB.
aredy29
Messages
10
Reaction score
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
still not clear..
 
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
 
how should I define my function ? I keep getting 'm power error'
 
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.
 
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
 

Similar threads

Replies
8
Views
2K
Replies
4
Views
1K
Replies
4
Views
2K
Replies
1
Views
2K
Replies
5
Views
2K
Replies
3
Views
2K
Back
Top