Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Error : In an assignment A(I) = B, the number of elements in B and I must be the same. Help !!!!

조회 수: 1 (최근 30일)
Ahmad Sheikh
Ahmad Sheikh 2015년 6월 19일
마감: MATLAB Answer Bot 2021년 8월 20일
I am working on takagi sugeno fuzzy modelling and a write a code like but its giving an error i dont understand why my function is like this.
function derivative_x = project_aft(t,x)
derivative_x=zeros(5,1);
z1 = 1342999.9 .* x(1) .* x(2) - 1342999.9 .* x(1) .* 1.1983 + 7748604.2 .* q .* x(2) + 7748604.2 .* x(3) .*1 - 172.19 .* 1.962.* x(2) + 172.19 .*1.962;
z2 = 684505.6 .* ( 1.962 + 11.1 .* (x(3) ./ (x(1).^2)));
z3 = (3874302.146 ./ x(1)) .* (1.962 .* x(2) +1.962);
a1 = 0.0269;
a2 = -0.0660;
b1 = -7.91;
b2 = -8.73;
c1 = -0.923;
c2 = -2.09;
a= a1-a2;
b= b1-b2;
c= c1-c2;
M11= (a1 - z1) ./ a;
M21= (z1 - a2) ./ a;
M12= (b1 - z2) ./ b;
M22= (z2 - b2) ./ b;
M13= (c1 - z3) ./ c;
M23= (z3 - c2) ./ c;
h1= M11* M12* M13
h2= M11* M12* M23
h3= M11* M22* M13
h4= M11* M22* M23
h5= M21* M12* M13
h6= M21* M12* M23
h7= M21* M22* M13
h8= M21* M22* M23
h=h1+h2+h3+h4+h5+h6+h7+h8
derivative_x(1)= 0.0001.*h1.*x(1)-1.4915.*h1.*x(2)-1.1387.*h1.*x(3)+14.9782.*h1.*x(4)-0.0001.*h1.*x(5)-0.0001.*h2.*x(1)-1.4915.*h2.*x(2)-1.1370.*h2.*x(3)+14.9782.*h2.*x(4)-0.0001.*h2.*x(5)-0.0001.*h3.*x(1)-1.4914.*h3.*x(2)-1.1387.*h3.*x(3)+14.9782.*h3.*x(4)-0.0001.*h3.*x(5)-0.0001.*h4.*x(1)-1.4914.*h4.*x(2)-1.1371.*h4.*x(3)+14.9782.*h4.*x(4)-0.0001.*h4.*x(5)-1.4915.*h5.*x(2)-1.1385.*h5.*x(3)+14.9784.*h5.*x(4)-0.0001.*h5.*x(5)-1.4915.*h6.*x(2)-1.1369.*h6.*x(3)+14.9784.*h6.*x(4)-0.0001.*h6.*x(5)-1.4914.*h7.*x(2)-1.1386.*h7.*x(3)+14.9784.*h7.*x(4)-0.0001.*h7.*x(5)-1.4914.*h8.*x(2)-1.1370.*h8.*x(3)+14.9784.*h8.*x(4)-0.0001.*h8.*x(5);
In simple
8
derivative_x(1)= h(i) [A(i) * x]
i=1
the other editor file where i called the above function is
Initial_Time=0;
Final_Time=100;
[x1,x2] = meshgrid(-2:0.1:2);
[t,x] = ode45(@project_aft, [Initial_Time Final_Time], [0 10 0 0 0]);
plot(t,x(:,1));
xlabel('time')
ylabel('state x1k')
  댓글 수: 2
Guillaume
Guillaume 2015년 6월 19일
Please, give us the entire error message (everything in red), particularly the part that shows the line where the error occurs.
Note that instead of writing a very long expression which increases the risk of mistakes, you would be much better off storing your h and A in a column vector, that is:
h = [M11 .* M12 .* M13;
M11 .* M12 .* M13;
...
M21 .* M22 .* M23];
A = [0.0001; -1.4915; ....; -0.0001];
Then derivative_x(1) is simply:
derivative_x(1) = sum(h .* A .* x);

답변 (0개)

이 질문은 마감되었습니다.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by