Error using sym>convertChar (line 1459)
17 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I need some help of my code. What's wrong with this code ?
>> clear all; clf
>> syms y t x z
>> % input a unit-step (heaviside) response
>> y = dsolve('D2y + 5*Dy + 6*y = heaviside(t)','y(0) = 0','Dy(0) = 0','t');
Error using sym>convertChar (line 1459)
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 1225)
S = convertChar(x);
Error in sym (line 214)
S.s = tomupad(x);
Error in dsolve>mupadDsolve (line 327)
sys = [sys_sym sym(sys_str)];
Error in dsolve (line 189)
sol = mupadDsolve(args, options);
>>
I attach dsolve.m and heaviside.m with this form.
this is my code.

original code from this

0 comentarios
Respuestas (3)
Uriel Gabriel Zapata Rodríguez
el 24 de Abr. de 2020
Editada: Steven Lord
el 24 de Abr. de 2020
i have the same problem with this code and nobody is here :'(
a=input('Enter the function in the form of variable x:','s');
x(1)=input('Enter Initial Guess:');
error=input('Enter allowed Error:');
f=inline(a)
dif=diff(sym(a));
d=inline(dif);
for i=1:100
x(i+1)=x(i)-((f(x(i))/d(x(i))));
err(i)=abs((x(i+1)-x(i))/x(i));
if err(i)<error
break
end
end
root=x(i)
[SL: Formatted code as code]
1 comentario
Steven Lord
el 24 de Abr. de 2020
First, you shouldn't use error as the name of your variable. It already has a meaning in MATLAB.
Second, you shouldn't use inline. If you want to convert the text the user has entered into a function, use str2func to turn it into a function handle. If you want to convert it into a sym object use str2sym.
Uriel Gabriel Zapata Rodríguez
el 24 de Abr. de 2020
%newton-raphson method
a=input('Enter the function in the form of variable x:','s');
x(1)=input('Enter Initial Guess:');
error=input('Enter allowed Error:');
f=inline(a)
dif=diff(sym(a));
d=inline(dif);
for i=1:100
x(i+1)=x(i)-((f(x(i))/d(x(i))));
err(i)=abs((x(i+1)-x(i))/x(i));
if err(i)<error
break
end
end
root=x(i)
0 comentarios
Steven Lord
el 24 de Abr. de 2020
As stated in the Note at the top of the documentation page for dsolve "Support for character vector or string inputs will be removed in a future release. Instead, use syms to declare variables and replace inputs such as dsolve('Dy = y') with syms y(t); dsolve(diff(y,t) == y)."
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!