Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

unit step , ramp functions

697 views
Skip to first unread message

kailatzakis

unread,
Dec 22, 2010, 3:11:20 PM12/22/10
to
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

Walter Roberson

unread,
Dec 22, 2010, 3:42:48 PM12/22/10
to

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.

kailatzakis

unread,
Dec 22, 2010, 3:54:07 PM12/22/10
to
"kailatzakis " <pns...@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));

Walter Roberson

unread,
Dec 22, 2010, 4:04:17 PM12/22/10
to
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".

aerielco...@gmail.com

unread,
Mar 2, 2013, 10:56:18 PM3/2/13
to
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 new messages