Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

2D plot of a function WITH MATLAB

  1. Jan 31, 2012 #1
    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.
     
  2. jcsd
  3. Jan 31, 2012 #2

    jedishrfu

    Staff: Mentor

  4. Jan 31, 2012 #3
    still not clear..
     
  5. Jan 31, 2012 #4

    jedishrfu

    Staff: Mentor

    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
     
  6. Jan 31, 2012 #5
    how should I define my function ? I keep getting 'm power error'
     
  7. Jan 31, 2012 #6

    jedishrfu

    Staff: Mentor

    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.
     
  8. Jan 31, 2012 #7

    jedishrfu

    Staff: Mentor

    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
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: 2D plot of a function WITH MATLAB
Loading...