MATLAB Help

This is a discussion on MATLAB Help within the Tech Board forums, part of the Community Boards category; I have been trying to write an m file in matlab which can plot a function which changes within the ...

  1. #1
    Lrnr
    Guest

    Question MATLAB Help

    I have been trying to write an m file in matlab which can plot a
    function which changes within the limits.

    I can plot a function within a given limit. But the function I
    have to plot is discontinuous.

    The function is

    y = exp(x+1) x < -1
    y = 2 + cos(pi*x) -1 <= x < 5
    y = 10(x - 5) + 1 x >=5


    And I want to plot y for -2 < x < 6


    I can plot if it is simply y = exp(x+1) for -2 < x < 6
    but there are three conditions on the top. how do i
    write the m file ?


    thanks

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    Using the different intervals perhaps? First plot from -2 to -1, then from -1 to 5 and finally from 5 to 6. You could put that into the array in which you store the signal and then plot the array.

  3. #3
    Lrnr
    Guest

    Unhappy Here's what I tried so far

    Here's what I tried so far... it doesn't work though.. it says the vectors are not equal. i am a beginner, i dont know what it is talking about.

    for x = [-2 : 1 : 6]
    if x < -1
    i = [-2 : 0.1 : -9.9];
    u = polyval(exp(i+1), i);
    end

    if x >= -1
    if x < 5
    j = [-1 : 0.1 : 4.8];
    v = polyval(2 + cos(pi*j), j);
    end
    end

    if x > 5
    k = [5 : 0.1 : 6];
    w = polyval(10*(k-5)+1, k);
    end
    end

    x = [-2 : .1 : 5.9];

    plot (x, u, x, v, x, w)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Convert Matlab Algebraic Sol to C compatible
    By Takeshi in forum C Programming
    Replies: 3
    Last Post: 01-08-2009, 05:35 PM
  2. MATLAB error
    By chico1st in forum Tech Board
    Replies: 1
    Last Post: 06-17-2008, 03:39 PM
  3. MATLAB importing C libraries
    By chico1st in forum C Programming
    Replies: 1
    Last Post: 05-29-2008, 02:01 PM
  4. C/C++ and Matlab?
    By darkwalk in forum C++ Programming
    Replies: 2
    Last Post: 10-21-2006, 03:00 AM
  5. HELP in MATLAB to C conversion
    By itachi in forum Tech Board
    Replies: 0
    Last Post: 01-08-2006, 01:26 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21