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*chebyshevT(i-1,2*x(r)-1)). How can I fix that?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Surath Ghosh
el 19 de Sept. de 2020
Comentada: Surath Ghosh
el 21 de Sept. de 2020
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
6 comentarios
Walter Roberson
el 20 de Sept. de 2020
g1{r}(u) = sym(0);
That syntax is the same as
g1{r} = symfun(sym(0), u)
which builds a symbolic function which accepts three distinct inputs and returns a value.
g1{r}(u)=g1{r}(u)+(u{i}-v(i))./(5)*chebyshevT(i-1,2*x(r)-1)
That code attempts to call g1{r} with a single input that is a vector of length 3.
To call g1{r} you need to pass in the elements of u as distinct inputs.
Using u{i}, I got u{1}=u1, u{2}=u2, u{3}=u3.
Which MATLAB release are you using? It would take me a bit of time to get a working copy of the old Maple-based MATLAB to test to be absolutely sure, but I guarantee that in any MuPAD based release of the symbolic toolbox, that what you indicate is incorrect.
m=3;
u=sym('u',[1,m]);
i = 1;
u{i}
Brace indexing is not supported for variables of this type.
Error in sym/subsref (line 907)
R_tilde = builtin('subsref',L_tilde,Idx);
{} is not valid for vectors of symbolic expressions.
It is not productive for me to keep arguing with you. Here is the code. Notice the complete lack of {} indexing for the symbolic vector.
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
I had to change the size of some of the arrays to fit your code. I took your "r=1:m-1" and "i=1:m+1" to be definite truths and repaired everything around those lines. That requires that u become a vector of length m+1 instead of length m, because you index u at i and i goes to m+1 . I had to assume that something was right about your code...
Respuesta aceptada
Walter Roberson
el 21 de Sept. de 2020
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.
Más respuestas (1)
Surath Ghosh
el 21 de Sept. de 2020
1 comentario
Walter Roberson
el 21 de Sept. de 2020
I guarantee that in that release you cannot use {} indexing of symbolic vectors.
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!