How can I plot a figure with multiplying a vector with matrices?

10 次查看(过去 30 天)
How can I plot the below figure in matlab?
I tried the below source code:
[X,Y] = meshgrid(-6:0.1:6);
Z = [X Y].*[2 1;1 3].*([X Y].') + [1 2].*[X Y].' + 3;
surf(X,Y,Z)
colormap(jet)
colorbar
and
[X,Y] = meshgrid(-6:0.1:6);
Z = [X Y]*[2 1;1 3]*([X Y].') + [1 2]*[X Y].' + 3;
surf(X,Y,Z)
colormap(jet)
colorbar
However, it showed the errors:
Error using .*
Matrix dimensions must agree.
Error in Fig20_3 (line 2)
Z = [X Y].*[2 1;1 3].*([X Y].') + [1 2].*[X Y].' + 3;
and
Error using *
Inner matrix dimensions must agree.
Error in Fig20_3 (line 2)
Z = [X Y]*[2 1;1 3]*([X Y].') + [1 2]*[X Y].' + 3;

回答(2 个)

Walter Roberson
Walter Roberson 2020-7-29
This is a case where you need the * operator instead of the .* operator
  4 个评论
Walter Roberson
Walter Roberson 2020-7-30
I think it might be easiest to expand the expression:
[X,Y] = meshgrid(-6:0.1:6);
Z = X + 2*Y + X .* (2*X + Y) + Y .* (X + 3*Y) + 3;
surf(X, Y, Z, 'edgecolor', 'none')

请先登录,再进行评论。


madhan ravi
madhan ravi 2020-7-28

类别

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