Hey all,
I'm attempting to write a program where I plot 3 different functions (x1, x2, x3) for three different time intervals.
For -4 < t < -2 : x1 = (t.^2) – (2*t) + 3
For -2 < t < 2 : x2 = 4cos((2*pi*t) – (pi/8)) + 3sin(2*pi*t)
For 2 < t < 4 : x3 = sinc(t)
When I try to implement my code I get straight lines in my plot which I know aren't correct. I'm struggling with how to set 't' equal to a range of values between two numbers not including those two numbers (ie -4 < t < -2). I know this is fairly simple if 't' was => -4 and =< -2 (ie t = -4:0.1:-2) but I need the starting and ending values to be excluded I'm attempting to do this without any if statements as well. Below is my code:
t = -4:0.1:4;t1 = (t>-4) & (t<-2);t2 = (t>-2) & (t<2);t3 = (t>2) & (t<4);x1 = (t1.^2) - (2*t1) + 3x2 = 4*cos((2*pi*t2) - (pi/8)) + 3*sin(2*pi*t2)x3 = sinc(t3);plot(t1,x1,t2,x2,t3,x3)
Best Answer