Error using * Inner matrix dimensions must agree.

21 次查看(过去 30 天)
When i type
x2=rot*x1;
This error message appear
Error using * Inner matrix dimensions must agree.
with
rot =
0.900736738123452 0.43436543208999
-0.43436543208999 0.900736738123452
x1 =
3 791
8 388
10 570
17 285
24 836
32 342
35 656
43 339
44 634
53 656
55 445
57 657
59 179
60 62
62 217
64 618
73 629
74 629
77 617
84 867
126 401
133 920
138 82
141 386
158 528
168 65
184 660
191 650
198 13
208 537
219 730
224 524
227 527
230 957
233 955
236 954
253 89
253 917
258 964
263 836
275 478
285 622
289 240
292 418
295 747
297 748
297 946
299 782
311 395
317 777
318 105
322 166
326 792
355 927
360 103
372 853
384 110
387 534
387 574
391 421
398 579
404 702
419 324
422 323
424 374
425 908
435 101
443 30
464 761
468 899
470 897
471 494
475 754
488 888
496 707
496 799
505 565
506 567
513 551
517 878
523 531
528 460
542 187
555 210
558 449
572 404
576 403
577 597
583 397
588 711
592 245
595 873
596 83
621 4
621 900
627 692
650 559
654 558
656 870
663 83
665 444
665 665
666 412
669 155
669 552
672 361
673 359
673 485
680 660
685 486
694 352
695 711
698 650
709 231
712 624
728 435
731 891
732 309
733 81
737 421
737 425
742 53
743 51
746 839
747 842
752 347
753 84
755 879
771 9
776 328
778 395
829 338
829 340
836 333
853 324
863 370
913 581
917 644
926 455
936 396
943 741
949 609
949 620
954 332
959 169
966 329
967 327
972 725
Can any one help me
to solve this problem
please!
thx

回答(4 个)

the cyclist
the cyclist 2014-5-20
编辑:the cyclist 2014-5-20
When you do a matrix multiplication A*B, the number of columns of A must be equal to the number of rows of B. That is basic matrix algebra.

alejandro hernandez
编辑:Walter Roberson 2017-4-19
clear all
T=0.1;
L=0/4;
L1=1/4;
L2=2/4;
L3=3/4;
L4=1;
A=[0 1;0 0];
I=[1 0;0 1];
B=[0 0;0 1];
M=10;
x=[1 1];
for i=2:M
x(i+1)=(T/L)*(A)-(1/L)+2*(I)*x+(T/L)*(B)*(2)+(1/L)*(I)-1*x;
end
Error using *
Inner matrix dimensions must agree.
Error in centrales_ponderadas (line 16)
x(i+1)=(T/L)*(A)-(1/L)+2*(I)*x+(T/L)*(B)*(2)+(1/L)*(I)-1*x;
  2 个评论
Walter Roberson
Walter Roberson 2017-4-19
Did you notice that you have a number of divisions by 0? You are dividing by L and L is 0.
Walter Roberson
Walter Roberson 2017-4-19
In the sub-expression 2*(I)*x, I is 2 by 2, and x is 1 x 2 to start, so I*x is a 2 x 2 * 1 x 2 which is not permitted because the inner dimensions do not match.
Your T and L are scalars and your A is 2 x 2, so (T/L)*A is scalar * 2 x 2 which is going to give you 2 x 2, so we know that the rest of the added terms are intended to give a 2 x 2 result. Your 2*(I)*x term must give a 2 x 2 result to match the (T/L)*A term.
But suppose that you managed to do that, and suppose the rest of the terms matched in size. Then the result would be 2 x 2, and you would be trying to assign that 2 x 2 value into the single location x(i+1)
If you manage to select a single element out to store into x(i+1) then x is going to become one element longer. That is important when you reach the 2*(I)*x in the next iteration: it will be a larger result than in the previous iteration and that makes it even less likely that you could correctly select out the one single value from the expression to store into x(i+1) that round.

请先登录,再进行评论。


rana vijay singh fezah
编辑:Walter Roberson 2018-4-10
t = 0:0.01:10;
>> u = 9.7*t + pi/2;
>> y = exp(-8*t) *sin(u);
Error using *
Inner matrix dimensions must agree.
>> y = exp(-8*t) * sin(u);
Error using *
Inner matrix dimensions must agree.
CAN SOMEONE SOLVE THIS!!!!
  1 个评论
Walter Roberson
Walter Roberson 2018-4-10
  • is algebraic matrix multiplication in MATLAB. For A*B, size(A,2) must equal size(B,1) -- columns of the first must equal rows of the second, with the result being size(A,1) by size(B,2)
You want element-by-element multiplication, which is .* instead of *
exp(-8*t) .* sin(u)

请先登录,再进行评论。


Cristian Rosca
Cristian Rosca 2020-9-5
if i have
>> a=-pi/2;
>> b=3*pi/2;
>> N=7;
>> h=(b-a)/(N-1);
>> x=a:h:b;
>> y=(x.^2)*log(abs(x)+1)*xcos(x);
Error using *
Inner matrix dimensions must agree.

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by