Matrix dimensions must agree in a function with the sum

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by