我创建了一个符号表达式,然后尝试在其上使用ezmesh
,如下面的代码所示:
>> z1 = sym('3*(1-x)^2*exp(-(x^2)-(y+1)^2)');
>> z2 = sym('-10*(x/5 - x^3 -Y^5)*exp(-x^2-y^2)');
>> z3 = sym(' - 1/3*exp(-(x+1)*2 - y^2)');
>> z = z1 + z2 + z3
z =
3*exp(- (y + 1)^2 - x^2)*(x - 1)^2 - exp(- y^2 - 2*x - 2)/3 + 10*exp(- x^2 - y^2)*(Y^5 + x^3 - x/5)
>> ezmesh(z)
我收到以下错误:
Error using ezgraph3>ezfixfun (line 677) The expression exp(x.*-2.0-y.^2-2.0).*(-1.0./3.0)+exp(-(y+1.0).^2-x.^2).*(x-1.0).^2.*3.0+exp(-x.^2-y.^2).*(x.*(-1.0./5.0)+Y.^5+x.^3).*1.0e1 must only have 2 symbolic variables Error in ezgraph3>surfplot (line 535) [F,var] = ezfixfun(F,fargs,flabel); Error in ezgraph3 (line 48) [dummy,h] = surfplot(f,domain,surfstyle,cax,Npts,fixdomain,flabel,fargs); Error in ezmesh (line 65) h = ezgraph3('mesh',args{:}); Error in sym/ezhelper (line 1074) fcn(F,varargin{:}); Error in sym/ezmesh (line 51) ezhelper(@ezmesh,f,varargin{:});
然而,当我在文档中查找峰值函数时,我发现了一个与ezmesh
一致的非常相似的表达式。任何人都可以解释这些差异吗?
z = 3*(1-x).^2.*exp(-(x.^2) - (y+1).^2) ...
- 10*(x/5 - x.^3 - y.^5).*exp(-x.^2-y.^2) ...
- 1/3*exp(-(x+1).^2 - y.^2)
答案 0 :(得分:1)
错误"必须只有2个符号变量"意味着有超过2个变量。
您在一个地方而不是Y
有一个大写y
,已修复:
z1 = sym('3*(1-x)^2*exp(-(x^2)-(y+1)^2)');
z2 = sym('-10*(x/5 - x^3 -y^5)*exp(-x^2-y^2)');
z3 = sym(' - 1/3*exp(-(x+1)*2 - y^2)');
z = z1 + z2 + z3;
ezmesh(z)