Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Getting the error of inner dimensions must agree

1 Ansicht (letzte 30 Tage)
Abdullah Nasir
Abdullah Nasir am 3 Feb. 2018
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
Below is the code for which I am getting the error
deltapsi=(-40:5:30)
deltathi=(9*(deltapsi.^2))/(8*3.142);
p=1
S=sin(deltathi-deltapsi)-(p*sin(deltapsi)*sin(deltathi));
The error is
Error using *
Inner matrix dimensions must agree.
Error in Untitled (line 4)
S=sin(deltathi-deltapsi)-(p*sin(deltapsi)*sin(deltathi));
I need to plot S versus deltapsi

Antworten (2)

Walter Roberson
Walter Roberson am 3 Feb. 2018
Use .* instead of *

Abdullah Nasir
Abdullah Nasir am 3 Feb. 2018
Thank you for the help Can I know the explanation where was I wrong
  1 Kommentar
Walter Roberson
Walter Roberson am 6 Feb. 2018
The .* operator is formally called times and multiplies corresponding elements in two arrays that are the same size. It can be used for arrays of more than 2 dimensions. https://www.mathworks.com/help/matlab/ref/times.html
The * operator that you used is formally called mtimes, and is algebraic matrix multiplication. The two arrays it multiplies are not generally the same size, but must be 2D, and the number of columns of the first array must equal the number of rows of the second array -- P x N * N x Q giving P x Q. https://www.mathworks.com/help/matlab/ref/mtimes.html

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by