unit step , ramp functions

  • Permalink
  • submit to reddit
  • Email
  • Follow


hello am trying to create new unit step and unit ramp function using matlab language and use them to get a plot for a specific equation 

i have created the the code below but still getting some errors that i cannot identify..

function k=step(t)

k = t>=0;

function k = ramp(t)

if t >= 0 
    k=t;
else
    t<0
    k=0;
end

t=-5:5;

f = zeros(size(t));

for x = 1:length(t)
    
    f(t)= (5*ramp(t+3))- ramp(t+1) - (3.*ramp(t))+ (5*ramp(t-1)) + (3*step(t-2));
    

end


plot(t,f)

anyone can help please? 

thanks in advance
0
Reply kailatzakis 12/22/2010 8:11:20 PM

See related articles to this posting


On 10-12-22 02:11 PM, kailatzakis wrote:
> hello am trying to create new unit step and unit ramp function using matlab
> language and use them to get a plot for a specific equation
> i have created the the code below but still getting some errors that i cannot
> identify..
>
> function k=step(t)
>
> k = t>=0;
>
> function k = ramp(t)
>
> if t >= 0 k=t;
> else
> t<0
> k=0;
> end
>
> t=-5:5;
>
> f = zeros(size(t));
>
> for x = 1:length(t)
> f(t)= (5*ramp(t+3))- ramp(t+1) - (3.*ramp(t))+ (5*ramp(t-1)) + (3*step(t-2));
>
> end
>
>
> plot(t,f)
>
> anyone can help please?

Change the assignment from f(t) on the left hand side to f(x) on the left hand 
side.


Also, I would point out that your ramp function is equivalent to max(0,t) . If 
you were to change it to that, then both step() and ramp() would be vectorized 
and you would then not need a loop to calculate your f.
0
Reply Walter 12/22/2010 8:42:48 PM

"kailatzakis " <pns2050@yahoo.com> wrote in message <ietm18$j2n$1@fred.mathworks.com>...
> hello am trying to create new unit step and unit ramp function using matlab language and use them to get a plot for a specific equation 
> 
> i have created the the code below but still getting some errors that i cannot identify..
> 
> function k=step(t)
> 
> k = t>=0;
> 
> function k = ramp(t)
> 
> if t >= 0 
>     k=t;
> else
>     t<0
>     k=0;
> end
> 
> t=-5:5;
> 
> f = zeros(size(t));
> 
> for x = 1:length(t)
>     
>     f(x)= (5*ramp(t+3))- ramp(t+1) - (3.*ramp(t))+ (5*ramp(t-1)) + (3*step(t-2));
>     
> 
> end
> 
> 
> plot(t,f)
> 
> anyone can help please? 
> 
> thanks in advance


yes i identified this mistake but still getting this error ..

???  In an assignment  A(I) = B, the number of elements in B and
 I must be the same.

Error in ==> rampstep at 7
    f(x)= (5.*ramp(t+3))- ramp(t+1) - (3.*ramp(t))+ (5.*ramp(t-1)) +
    (3.*step(t-2));
0
Reply kailatzakis 12/22/2010 8:54:07 PM

On 10-12-22 02:54 PM, kailatzakis wrote:

> yes i identified this mistake but still getting this error ..
>
> ??? In an assignment A(I) = B, the number of elements in B and
> I must be the same.
>
> Error in ==> rampstep at 7
> f(x)= (5.*ramp(t+3))- ramp(t+1) - (3.*ramp(t))+ (5.*ramp(t-1)) +
> (3.*step(t-2));

All the "t" on the right hand side should be "x".
0
Reply Walter 12/22/2010 9:04:17 PM

Given a current step function:

    T= 1e-9 * input('  simulated time [ns]: ');   		% simulated time [s]
    disp(dt);
    ct = round(T/dt); # time elements
    t=0:dt:ct*dt;									% time vector
    Ion=1e-3*input('  DC max current [mA]: ');		% DC current [A]
    I=repmat(Ion, [1, ct+1]);
    I(1,1)=0;

how can I make a ramp function?
0
Reply aerielconstantino (1) 3/3/2013 3:56:18 AM
comp.soft-sys.matlab 203406 articles. 529 followers. Post

4 Replies
3242 Views

Similar Articles

[PageSpeed] 10


  • Permalink
  • submit to reddit
  • Email
  • Follow


Reply:

Similar Artilces:

Errors in plotting Unit Step Function and Ramp Function !!!!
t = -10:0.1:10; % Unit Step Function y(t>=0) = 1; y(t<0) = 0; plot(t,y) %% t = -2 :0.001: 2; % Unit Impulse....... y(t==0) = 1; y(t~=0) = 0; plot(t,y) %% t = -2 : 0.001 : 2; %Ramp Function y(t>=0) = t; y(t<0) = 0; plot(t,y) %% For the Unit Step I am getting an error ??? Error using ==> plot Vectors must be the same lengths. For the Impulse func. if I change 't = -2 : 0.001 : 2 ' .... to something other like t = -10 :0.1 :10.... Please help me removing those errors !!!! For the Ramp.... ??? In an assignment A(:) = B, th...

Unit Step Function
I just received my 49G+ the 10 of January. I have used a 48SX/GX for sometime. What I am trying find is how to program in the unit step function into this calculator [an example would be: f(t)u(t), f(t-a)u(t), etc. from the Laplace Transform Tables]. I will taking a Linear Signal and Systems Class this Spring and I would like to use the Calculator help me verify my answers both on Homework and on the tests. I have never tried to do this on the calculator. I would appreciate any help with this. Thank-you. Dennis Dennis E Ahner wrote: > I just received my 49G+ the 10 of January. I have u...

unit step function
I'm trying to graph the unit step function u(t), e.g., u(t) = 1 for t>0 and u(t) = 0 for t<0. I created a function (M-file), function t = u(t); t>0 but I keep getting a straight line in the form of y = x. I tried using, t=[0:10]; plot(t, u(t)) I received an answer of [0 1 1 1 1 1 1 1 1 1 1] on the command window, but I got aforementioned line. Next, I tried replacing the output variable t with s, but that was worse. I received an error message saying I did not assign the output variable anything. No graph. Any help appreciated. Aaron Friedman wrote: > ...

Unit step functions
How do i represent these unctions in MATLAB 7: t*cos(10*pi*t)*e^-2|t|*[u(t+2)-u(t-2)] and sin(10*pi*t)*[u(t+2)-u(t-2)} I have been looking for a way to do it for about an hour and a half now. This is what I have so far. y_1 = t .* cos(10*pi*t) .* exp(-2*abs(t)) .* [u(t+2)-u(t-2)]; y_2 = sin(10*pi*t) .* [u(t+2)-u(t-2)]; I can't figure out how to input the Step Function. Any help would be appreciated. Hi Jon, take a look for the laplace- and z-transform. Additionally u(t+2) is an interesting term! Regards, Stefan > and > > sin(10*pi*t)*[u(t+2)-u(t-2)} > > I have been...

unit step function
Hi &nbsp; Can somebody help me on&nbsp;developing a code for unit step function? Thanks Why did you create a new message?&nbsp; Please keep your questions to the <a href="http://forums.ni.com/ni/board/message?board.id=170&amp;view=by_date_ascending&amp;message.id=345259#M345259" target="_blank">original thread</a>&nbsp;where you already started receiving help. Message Edited by Ravens Fan on 08-04-2008 11:04 PM ...

plotting unit step functions
Hi am trying to plot the unit step function u(t-1)-u(t-2)+u(2-t)-u(3-t)+u(t-3)-u(t-4) just not sure how to start it. Thanks ...

How to create a unit step function??
I need to plot the following: x1(t)= tu(t)-tu(t-1) this is what i've done so far to deal with the u(t-1) part: (disregard the numbers here as i've yet to define my interval) u=zeros(11,1); u(6:end)=1; this gives me a column with the first five rows being 0 and the rest 1 i thought i could multiply this with t to get the desired effect, but understandably i get an 11x11 matrix and i can't really plot this vs time please help... "Miguel Bustelo" wrote in message <igjek5$3jc$1@fred.mathworks.com>... > I need to plot the following: x1(t)= tu(t)-tu...

Unit Step Function #3
How do I plot a step function? I'm supposed to plot: x[n] = u[n] + u[-n] from -20 to 20 and determine if it is a periodic function. I'm inclined to say it's not, as the function would always equal 1 and not oscillate. I'm not entirely sure though. I realize this is probably very simple, but I don't have a programming bone in my body and don't retain this stuff very well. "Ragan " <ragan.pitner@gmail.com> wrote in message <habita$lff$1@fred.mathworks.com>... > How do I plot a step function? > > I'm supposed to plot: > > x[n...

How to do step,impulse and ramp functions
Hi I am having difficulty in understanding how to come about using the info provided by help. So if anybody could help ,e would be great. I need to generate IMPULSE function for: y=zeros(1,5) y=[1; zeros(99,1)]; STEP function: y=ones(100,1); RAMP function: y=t; plot(t,y) I do not know the lines of codes to put in to do the above. If someone could show me. Thank you ...

unit step function #2 815532
I can not find the unit step function , u(t), in matlab. Please can anyone who knows help me? levent wrote: > I can not find the unit step function , u(t), in matlab. > Please can anyone who knows help me? > I'm not sure what you mean, but did you try "help step"? or just "step" (this gives an example straight away)? If this is not what you mean, please explain a bit more... Jorg "levent" <leventseyfi@gmail.com> wrote in message news:55x715s09l0p@legacy... > I can not find the unit step function , u(t), in matlab. > Please can any...

Heaviside unit step function
Hi all, I want to plot 3 Heaviside step unit functions 1) u(t) 2) 4*u(t-1) 3) -5*u(t-1) where u(t) is the unit Heaviside step function Before that, how do write an equation using all three i.e dxdt = u(t) + 4*u(t-1) - 5*u(t-1) Thank you On 4/19/2012 3:20 AM, Sarah Coleman wrote: > Hi all, I want to plot 3 Heaviside step unit functions > > 1) u(t) > > 2) 4*u(t-1) > > 3) -5*u(t-1) > > where u(t) is the unit Heaviside step function > > Before that, how do write an equation using all three i.e > > dxdt = u(t) + 4*u(t-1) - 5*u(t-1) > ...

Unit step function #2 336644
How to manually write the code for a matlab unit step function, by user -written function. thanks Hind <hind2007@gmail.com> wrote in message <dff8cf82-4500-4a07-9af5-db6c862cd427@c39g2000yqi.googlegroups.com>... > How to manually write the code for a matlab unit step function, by > user -written function. > thanks ustep = @(x,range) range>=x; Mira On 12/22/2010 3:36 PM, Hind wrote: > How to manually write the code for a matlab unit step function, by > user -written function. > thanks You could aways use Matlab heaviside n = -10:10; ...

Cosine function convolve with Unit Step
Does anyone know the coding and what will happen when Cosine function convolve with Unit Step? Thanx ...

need help integrating the unit step function
I have the unit step function written as: function y=ustep(t) y=double(t>=0); and I need to evaluate: (b-3)^2*x(b) from -1 to 1 (with respect to b) where x(b)=[ustep(b)-ustep(b-0.1)]/0.1 I got an error saying it won't accept an input argument of type 'sym', so I defined x from -1 to 1 and it says the matrix must be square. Any suggestions on how to get around this? "Colleen " <wheniamqueen09@gmail.com> wrote in message <g27c47$kqq $1@fred.mathworks.com>... > I have the unit step function written as: > > function y=ustep(t) > ...

gaps between intervals of unit step function >
Hello, I want to plot a piecewise function, but I don't want any gaps to appear at the junctures, what terms should be added tp the function to avoid the gap between each interval, for example: t=[1:8784]; b=(26 + 13*sin(0.000853*t - 2.7773)).*((heaviside(t-2184))-(heaviside(t-7440))); plot(b,'r','LineWidth', 1.5);grid on I want the figure to be continueous without any gap. any idea to that .. regards any help, plese "MOOON MOOON" wrote in message <ifoikq$s8r$1@fred.mathworks.com>... > > Hello, > > ...

Delayed Unit Step (Heaviside) Function on Matlab
Hi, I'm trying to create a variable which holds a delayed unit step function which starts at 64 (rather than the normal unit step function which starts at 0). I named this variable Heavisidesixtyfour and used the following statement to try to implement it: heavisidesixtyfour=(t>=64); I also set the value at 63 (taking into account a problem I encountered recently which was resolved by including 0 time in my count). However, I am getting the following error message whichever way I try to run it: ??? Error using ==> mtimes Inner matrix dimensions must agree. I had previously cre...

Can MatLab plot Unit Step/Impulse Functions for Continuous time and Discrete time?
I am studying for a signals and systems processing exam. Part of the exam will be graphing unit step and impulse functions for Discreet and Continuous time signals. I want to use Matlab to verify that I am graphing these signals correctly. Can someone show me how? x[n]=2u[n]-4u[n-3]+2u[n-5] x(t)=tu(t)-(t-3)u(t-3)-(t-7)u(t-7)+(t-10)u(t-10) On 11/27/2013 5:57 PM, Dan wrote: > I am studying for a signals and systems processing exam. Part of the exam will be >graphing unit step and impulse functions for Discreet and Continuous time signals. >I want to use Matlab to verify that I...

step function and step block
When I use step function as follows: k=1.739e-5; num= k*188130436; den=[1 1588 188130436]; fn=tf(num,den); step(fn) and I tried another way:(simulink) step block ----> gain k -----> transfer function (num/den) ------> scope The results are quite different. How come?! ...

GUI units and function units
I want to customize the size of the GUI window to a 10cm x 10cm size. I have done so by changing the UNITS in the PropertyEditor. However, the CurrentPosition and Position displayed on the GUIDE are still in the default units. Furthermore, when I use functions like linspace(), the units used again the default units and not 'mm' as I would like it to be. Can someone suggest how do I achieve computations in mm/cm instead of the default 'characters' ? ...

running function step by step
How can I run a user function step by step like the debugger does? I'm searching a solution for C/C++. Thanks "razvan.marcus@gmail.com" wrote: > How can I run a user function step by step like the debugger does? I'm > searching a solution for C/C++. > > Thanks you would use the debug API to debug the program. The easiest thing to do is embed a breakpoint at the beginning of your function (so that it will be compiled in), then set the trace flag in EFLAGS when it is reached. Then the debugger will tell you after each instruction... bu...

how to use this function Invoke Node step by step
there is a function in voke node in the red area, whether somebody tell me how to use the function in this picture. ??1.png: http://forums.ni.com/attachments/ni/170/338552/1/??1.png <a href="http://forums.ni.com/ni/board/message?board.id=170&amp;view=by_date_ascending&amp;message.id=338555#M338555" target="_blank">Duplicate Post</a> how to get the group ??1.png: http://forums.ni.com/attachments/ni/170/339532/1/??1.png Hi roverboy, right-click on "Image" terminal, select create-&gt;invoke node... ...

how to use this function Invoke Node step by step #3
there is a function in voke node in the red area, whether somebody tell me how to use the function in this picture. ??12.png: http://forums.ni.com/attachments/ni/170/338555/1/??12.png Your picture does not show an invoke node or a red area at all.&nbsp; Can you please clarify your question? Hi roverboy, do you have another control/indicator with name "Image"? I think it�s an invoke node, right click on your control/indicator and select -&gt; create invoke node -&gt; Get Last Event. Hope it helps.Mike duplicate post, contiued <a href="http://forums.ni.com/ni/b...

how to use this function Invoke Node step by step #2
there is a function in voke node in the red area, whether somebody tell me how to use the function in this picture. ??11.png: http://forums.ni.com/attachments/ni/170/338554/1/??11.png <a href="http://forums.ni.com/ni/board/message?board.id=170&amp;view=by_date_ascending&amp;message.id=338555#M338555" target="_blank">Duplicate Post</a> ...

diff eq plotting piecewise functions or step functions
can anyone direct me as to how to plot a diff eq initial value equation and the step function it is set equal to? : y''''+5y'' +4y= 1 - U(pi)(t) <==== step function(subscript pi) how do i plot the U(pi)(t) function? do i need to turn it into piecewise? if so , then how do i plot the piecewise function? i soved the equation for y to get : y = h(t) - U(pi)(t)h(t-pi) where h(t) = (1/12)(3-4cos(t)+cos(2t) please help thanks so far i've tried the following : h:= (1/12)*(3-4*cos(t)+cos(2*t)) ; > h := 1/4 - 1/3 cos(...