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 |

12/22/2010 8:11:20 PM

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 |

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 |

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 |

12/22/2010 9:04:17 PM