Matlab基本脚本函数y(x)和sum

Matlab基本脚本函数y(x)和sum,matlab,Matlab,我试图在matlab中为θ0到3绘制这个函数。 我对matlab完全陌生。我做了两个脚本 首先使用symsum: syms theta u = [2,1,-1]; y = [3,2,1]; for theta = 0 : 0.1 : 2 Q(theta) = symsum((y(n) + u(n)*theta)^2,n,1,3); end plot(theta,Q(theta); 错误:索引或函数定义无效 第二个是symfun for theta = 0 : 0.1 : 2

我试图在matlab中为θ0到3绘制这个函数。 我对matlab完全陌生。我做了两个脚本

首先使用symsum:

syms theta
u = [2,1,-1];
y = [3,2,1];

for theta = 0 : 0.1 : 2 
    Q(theta) = symsum((y(n) + u(n)*theta)^2,n,1,3);
end

plot(theta,Q(theta);
错误:索引或函数定义无效

第二个是symfun

for theta = 0 : 0.1 : 2 
   Q = symfun((3-2*theta)^2 + (2-theta)^2 + (1+theta)^2, [theta]);
end
plot(Q(theta), theta);
错误:y.vars=validateArgNames(输入)


我想你只是想画出函数,然后下面的应该可以

theta = 0 : 0.1 : 2 ;
Q = (3-2*theta).^2 + (2-theta).^2 + (1+theta).^2;
plot(Q,theta)
如果要将
y
u
作为参数,还可以执行以下操作

y = [3,2,1];
u = [2,1,-1];
theta = 0:0.1:2;
Q = zeros(size(theta));
for i = 1:length(y)
   Q = Q +  (y(i) - u(i).*theta).^2;
end
plot(Q,theta);

我想你只是想画出函数,然后下面的应该可以

theta = 0 : 0.1 : 2 ;
Q = (3-2*theta).^2 + (2-theta).^2 + (1+theta).^2;
plot(Q,theta)
如果要将
y
u
作为参数,还可以执行以下操作

y = [3,2,1];
u = [2,1,-1];
theta = 0:0.1:2;
Q = zeros(size(theta));
for i = 1:length(y)
   Q = Q +  (y(i) - u(i).*theta).^2;
end
plot(Q,theta);

谢谢你,我会很快接受的!你知道我做错了什么吗?或者如何使用symsum?谢谢你,很快就会接受的!你知道我做错了什么吗?或者如何使用symsum?