syntax issues when adapting an old code from 2009a

2 views (last 30 days)
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 Comments
Andreas Roschger
Andreas Roschger on 24 Nov 2021
Edited: Andreas Roschger on 24 Nov 2021
Thanks for the quick reply, i now replaced the characters and added the definition of "r"
the code now reads:
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'.
Error in sym>tomupad (line 1253)
S = convertChar(x);
Error in sym (line 220)
S.s = tomupad(x);
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)'}));

Sign in to comment.

Answers (1)

Navya Singam
Navya Singam on 2 Dec 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.

Products


Release

R2009a

Community Treasure Hunt

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

Start Hunting!

Translated by