Matrix dimensions must agree in a function with the sum

1 回表示 (過去 30 日間)
Yuriy Yerin
Yuriy Yerin 2022 年 1 月 18 日
コメント済み: Torsten 2022 年 1 月 18 日
Hello everybody.
Sorry for a stupid question but can't resolve this problem.
How can I avoid the error "Matrix dimensions must agree" without implementation of two loops for two variables?
The code is below.
function z=coeff
n=0:1:100000;
t=linspace(0.5,1.25,100);
G=linspace(0.1,1,100);
[t G] = meshgrid(t,G);
b11= @(t, G) (pi*t.*(sum((((2*n+1).*pi.*t)+G).^4./(((2*n+1).*pi.*t).^3.*(((2*n+1).*pi.*t)+2*G).^4)))+...
pi*t*(sum((((2*n+1).*pi.*t)+G).*G.*(G.^2+3*G.*((2*n+1).*pi.*t)+((2*n+1).*pi.*t).^2)./(((2*n+1).*pi.*t).^3.*(((2*n+1).*pi.*t)+2*G).^4))));
z1=b11(t,G);
contourf(t,G,z1);
colormap jet
colorbar
set(gca,'FontName','Times New Roman','FontSize',34)
end
Many thanks in advance.
  1 件のコメント
Torsten
Torsten 2022 年 1 月 18 日
Insert the lines
size(t)
size(G)
size(n)
after the call to meshgrid.
These sizes must be equal in order for the function b11 to work. In your case, they are different.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeContour Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by