MATLAB: I got an error as symbolic function expected 3 inputs and received 1 in the line no 5 (g1{r}(u)=​g1{r}(u)+(​u{i}-u1(i)​)./5*cheby​shevT(i-1,​2*x(r)-1))​. How to fix that

cell arrayfunction

m=3;
u=sym('u',[1,m]);
g1 = cell(m+1, 1);
for r=1:m-1;
g1{r}(u) = sym(0);
for i = 1 : m+1
g1{r}(u)=g1{r}(u)+(u{i}-u1(i))./(5)*chebyshevT(i-1,2*x(r)-1);
end
end

Best Answer

m = 3;
x = rand(1,m-1); %replace with your actual data, which must be at least m-1 long
v = rand(1,m+1); %replace with your actual data, which must be at least m+1 long
u = sym('u',[1,m+1]);
uc = num2cell(u);
g1 = cell(m-1, 1);
for r=1:m-1
g1{r}(u) = sym(0);
for i = 1 : m+1
g1{r}(u)=g1{r}(uc{:})+(u(i)-v(i))./(5)*chebyshevT(i-1,2*x(r)-1);
end
end
Under the assumption that the two "for" lines were coded correctly by the user; everything else was modified to fit that.