matlabscilab

Incompatible dimensions [scilab]


i want to launch my program in scilab, but i got problem with incompatible dimensions and don't know how to fix it.

graphs must be like this

that's what i've used to write a code

x is (7/4)t for 0≤t<4
x is 7 for 4≤t<6
x is -t+13 for 6≤t<14
x is -7 for 14≤t<16
x is (7/4)t-7 for 16≤t<20

y is 1 for 0≤t<2
y is 3 for 2≤t<4

the biggest problem is what to do with t11-15 here is code i tried

m=10;N=2^m;
T1=20;
dt1=T1/N;
t1=0:dt1:T1-dt1;
t11=0:dt1:4-dt1;
t12=4:dt1:6-dt1;
t13=6:dt1:14-dt1;
t14=14:dt1:16-dt1;
t15=16:dt1:20-dt1;
x11=(7/4)*t11;
x12=7*ones(1,N/2);
x13=-t13+13;
x14=(-7)* ones(1,N/2);
x15=(7/4)*t15-7;
x=[x11 x12 x13 x14 x15];
T2=4;
dt2=T2/N;
t21=0:dt2:2-dt2;
t22=2:dt2:4-dt2;
t2=[t21 t22]
y21=1*ones(1,N/2);
y22=3*ones(1,N/2);
y=[y21 y22];
figure(1,'BackgroundColor',[1,1,1]);
plot2d2(t1,x,5);
plot2d2(t2,y,3)


Solution

  • The dimensions of x and t1 do not matches t1 has 1024 values and x has 1841 value. x12 and x14 do not have the proper sizes.

    a straight forward solution could be

    m=10;N=2^m;
    T1=20;
    dt1=T1/N;
    t1=0:dt1:T1-dt1;
    x=zeros(t1);
    i=t1<4;x(1,i)=t1(i)*7/4;
    i=t1>=4&t1<6;x(i)=7;
    i=t1>=6&t1<14;x(i)=-t1(i)+13;
    i=t1>=14&t1<16;x(i)=-7;
    i=t1>=16&t1<20;x(i)=-7+t1(i)*7/4;