unit step , ramp functions

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
kailatzakis
12/22/2010 8:11:20 PM
comp.soft-sys.matlab 209315 articles. 11 followers. lunamoonmoon (258) is leader. Post Follow

4 Replies
4400 Views

Similar Articles

[PageSpeed] 38

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
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
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
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
3/3/2013 3:56:18 AM
Reply: