Error using sym>convertChar (line 1448)

Hi everyone,
I get the error message:
"Error using sym>convertChar (line 1448) 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 1214) S = convertChar(x);
Error in sym (line 211) S.s = tomupad(x);
Error in SolveExample>TurnEqIntoDEq (line 43) depVarsLong(k) = sym([char(depVars(k)) '(' char(indepVar) ')']);
Error in SolveExample (line 21) [dEq3, initEq3] = TurnEqIntoDEq(Eq1, [a b c], t, 0);"
when I run the attached code. What can I do?

 Respuesta aceptada

Tiasa Ghosh
Tiasa Ghosh el 13 de Ag. de 2018
Editada: Tiasa Ghosh el 13 de Ag. de 2018

2 votos

You have used the function subs() for substitution in your function TurnEqIntoDEq . The input to subs (L47 in your code file) is a string. But the function 'subs' expects a symbolic variable or expression. So in the parent file, convert the Eq1 to symbolic string with str2sym and then pass it to TurnEqIntoDEq function. Also, use str2sym for depVarsLong(k) and depVarsShort(k) in TurnEqIntoDEq. I have done the same to the file attached.

6 comentarios

Dursman Mchabe
Dursman Mchabe el 13 de Ag. de 2018
Editada: Dursman Mchabe el 13 de Ag. de 2018
Thanks a lot, I try that immediately.
Tiasa Ghosh
Tiasa Ghosh el 13 de Ag. de 2018
Yes. I am using R2017b and that still works with a warning that the feature will be removed in next versions. Hence it doesn't work for 2018 versions.
Dursman Mchabe
Dursman Mchabe el 13 de Ag. de 2018
Editada: Dursman Mchabe el 13 de Ag. de 2018
Alternatively, I can re-install R2017b, if I don't succeed. Thanks a lot for helping me.
Tiasa Ghosh
Tiasa Ghosh el 13 de Ag. de 2018
The file which I have uploaded with my answer runs without any warning. I just mentioned what is the issue of your code. follow that. It should work.
Dursman Mchabe
Dursman Mchabe el 13 de Ag. de 2018
Thanks a lot. The code your amendments worked. I truly appreciate.
Dursman Mchabe
Dursman Mchabe el 13 de Ag. de 2018
Thanks a lot. The code you uploaded works. I truly appreciate.

Iniciar sesión para comentar.

Más respuestas (1)

ahmed
ahmed el 21 de Mayo de 2024
syms s U Y
% Define the Laplace transform of u(t) and y(t)
U = laplace(sym('u(t)', 't'), s);
Y = laplace(sym('y(t)', 't'), s);
% Define the differential equation in Laplace domain
eqn = 6*s^2*U - 3*U + Y/s == -3*s^3*Y - Y;
% Solve for the Laplace transform of the output Y(s)
Y_s = solve(eqn, Y);
% Define the Laplace transform of the input, U(s)
U_s = laplace(sym('u(t)', 't'), s);
% Calculate the transfer function H(s) = Y(s) / U(s)
H_s = simplify(Y_s / U_s);
% Display the transfer function
disp('Transfer Function:');
disp(H_s);

Etiquetas

Preguntada:

el 13 de Ag. de 2018

Respondida:

el 21 de Mayo de 2024

Community Treasure Hunt

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

Start Hunting!

Translated by