修正代码:for p=1:100 for m=1:15 dist2=sqrt((x01(p)-x0(m))^2); %gauss %f=w(m)*((dist2)^2+1)^0.5; z_g(p)=z_g(p)+w(m)*exp(-(dist2)/2*sigma^2); end z_real=sin(pi*x01(p)/2) + cos(pi*x01(p)/3); end figure(2) plot(x01,z_g', 'r-');
时间: 2024-02-06 13:02:45 浏览: 171
修正后的代码如下,主要是在计算高斯函数时加入了括号,同时调整了变量名的大小写:
```
for p = 1:100
for m = 1:15
dist2 = sqrt((x01(p) - x0(m))^2);
% gauss
% f = w(m) * ((dist2)^2 + 1)^0.5;
z_g(p) = z_g(p) + w(m) * exp(-(dist2)^2 / (2 * sigma^2));
end
z_real = sin(pi * x01(p) / 2) + cos(pi * x01(p) / 3);
end
figure(2)
plot(x01, z_g, 'r-');
```
阅读全文