# syntax issues when adapting an old code from 2009a

2 visualizaciones (últimos 30 días)
Andreas Roschger el 24 de Nov. de 2021
Respondida: Navya Singam el 2 de Dic. de 2021
Dear All,
I'm currently struggeling with adapting a short code from the book "Modeling of Curves and Surfaces with MATLAB" from 2010 based on Matlab 7.8 Release 2009a. I would like it to run under Matlab 2020a. The function in the book is presented as:
function f = sgeod(r)
syms u v;
ru = diff(r, u); rv = diff(r, v); % these 2 lines
E = ru*ru; F = ru*rv; G = rv*rv; % can be replaced by
% S=EFG(r); E = S(1); F = S(2); G = S(3); % the following line:
g = E*G - F*F;
Eu = diff(E, u); Ev = diff(E, v);
Fu = diff(F, u); Fv = diff(F, v);
Gu = diff(G, u); Gv = diff(G, v);
f(1)= simplify(-subs((G*Eu - F*(2*Fu - Ev))/(2*g)*x(3)*x(3)+ (G*Ev - F*Gu)/
g*x(3)*x(4)+G*(2*Fv - Gu) - F*Gv)/(2*g)*x(4)*x(4), {u v}, {x(1), x(2)}));
f(2) = simplify(-subs((E*(2*Fu -Ev) -F*Eu)/(2*g)*x(3)*x(3)+ (E*Gu - F*Ev)/
g*x(3)*x(4)+(E*Gv - F*(2*Fv - Gu))/(2*g)*x(4)*x(4), {u v}, {x(1), x(2)}));
end
It would be great if someone could help me with what would be the correct sytax for this code for matlab 2020a
thanks a lot and best greetings
Andreas
##### 2 comentariosMostrar NingunoOcultar Ninguno
Jan el 24 de Nov. de 2021
Most of all replace the ’ (char(8217)) characters by quotes: ' (char(39)) .
Then try it again. If you get an error message, post a copy of the complete message and explain, what you use as input r.
Andreas Roschger el 24 de Nov. de 2021
Editada: Andreas Roschger el 24 de Nov. de 2021
Thanks for the quick reply, i now replaced the characters and added the definition of "r"
syms u v;
r = [(5 + cos(u))*cos(v), (5 + cos(u))*sin(v), sin(u)];
ru = diff(r, u); rv = diff(r, v); % these 2 lines
E = ru*ru'; F = ru*rv'; G = rv*rv'; % can be replaced by
% S=EFG(r); E = S(1); F = S(2); G = S(3); % the following line:
g = E*G - F*F;
Eu = diff(E, u); Ev = diff(E, v);
Fu = diff(F, u); Fv = diff(F, v);
Gu = diff(G, u); Gv = diff(G, v);
f(1) = simplify(-subs((G*Eu - F*(2*Fu - Ev)) /(2*g)*'x(3)*x(3)'+ (G*Ev - F*Gu)/g*'x(3)*x(4)'+(G*(2*Fv - Gu) - F*Gv)/(2*g)*'x(4)*x(4)', {u v}, {'x(1)', 'x(2)'}));
f(2) = simplify(-subs((E*(2*Fu -Ev) -F*Eu) /(2*g)*'x(3)*x(3)'+ (E*Gu - F*Ev)/g*'x(3)*x(4)'+(E*Gv - F*(2*Fv - Gu))/(2*g)*'x(4)*x(4)', {u v}, {'x(1)', 'x(2)'}));
the syntax for x seems strage to me.
when i try to run that, the error message reads:
Error using sym>convertChar (line 1537)
Character vectors and strings in the first argument can only specify a variable or number. To evaluate character vectors and strings representing symbolic expressions, use 'str2sym'.
S = convertChar(x);
Error in sym (line 220)
Error in sym/privResolveArgs (line 1005)
argout{k} = sym(arg);
Error in sym/privBinaryOp (line 1029)
args = privResolveArgs(A, B);
Error in * (line 320)
X = privBinaryOp(A, B, 'symobj::mtimes');
Error in test123 (line 13)
f(1) = simplify(-subs((G*Eu - F*(2*Fu - Ev)) /(2*g)*'x(3)*x(3)'+ (G*Ev - F*Gu)/g*'x(3)*x(4)'+(G*(2*Fv - Gu) - F*Gv)/(2*g)*'x(4)*x(4)', {u v}, {'x(1)', 'x(2)'}));

Iniciar sesión para comentar.

### Respuestas (1)

Navya Singam el 2 de Dic. de 2021
Hi,
In this line of code,
f(1) = simplify(-subs((G*Eu - F*(2*Fu - Ev)) /(2*g)*'x(3)*x(3)'+ (G*Ev - F*Gu)/g*'x(3)*x(4)'+(G*(2*Fv - Gu) - F*Gv)/(2*g)*'x(4)*x(4)', {u v}, {'x(1)', 'x(2)'}));
"subs" function expects the first argument to be symbolic expression or symbolic function. But 'x(3)*x(3)' in first argument is of the type char, to convert it into symbolic expression you can use the str2sym function.
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre Common Operations en Help Center y File Exchange.

R2009a

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by