syntax issues when adapting an old code from 2009a
조회 수: 2 (최근 30일)
이전 댓글 표시
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
Jan
2021년 11월 24일
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.
답변 (1개)
Navya Singam
2021년 12월 2일
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
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!