Error using sym>convertChar

Error using sym>convertChar
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 1608)
S = convertChar(x);
Error in sym (line 400)
S.s = tomupad(x);
Error in sym/privResolveArgs (line 1180)
argout{k} = sym(arg);
Error in sym/diff (line 29)
args = privResolveArgs(S, invars{:});
Error in NEWTONRAPHSON/STARTButtonPushed (line 39)
df = diff(app.fun,x);
Error in matlab.apps.AppBase>@(source,event)executeCallback(appdesigner.internal.service.AppManagementService.instance(),app,callback,requiresEventData,event) (line 63)
newCallback = @(source, event)executeCallback(appdesigner.internal.service.AppManagementService.instance(), ...
Error while evaluating Button PrivateButtonPushedFcn.
HOW DO I SOLVE THIS PROBLEM

15 件のコメント

KSSV
KSSV 2022 年 5 月 27 日
Show us your code.
CHUNG SI HAO
CHUNG SI HAO 2022 年 5 月 27 日
syms x
df = diff(str2sym(app.fun,x));
app.dfdxEditField.value = char(df) ;
%Initial start
xold = app.StartingpointEditField.Value;
for i=1:app.NoofIterationEditField.Value
x = xold;
Function = eval(app.fun);
Derivative = eval(df);
xnew = xold - Function/Derivative;
AbsErr = abs(xold - xnew);
app.UITable.Data(i,:) = [i xold xnew Function AbsErr];
xold = xnew;
if AbsErr <= app.ToleranceEditField.Value
break
end
pause(1);
end
Walter Roberson
Walter Roberson 2022 年 5 月 27 日
eval() of a symbolic expression such as df has undefined results. You should never eval() anything symbolic. Use subs() instead.
CHUNG SI HAO
CHUNG SI HAO 2022 年 5 月 27 日
after i change eval() to subs()
it shows
Error using str2sym
Too many input arguments.
Error in NEWTONRAPHSON/STARTButtonPushed (line 39)
df = diff(str2sym(app.fun,x));
Error in matlab.apps.AppBase>@(source,event)executeCallback(appdesigner.internal.service.AppManagementService.instance(),app,callback,requiresEventData,event) (line 63)
newCallback = @(source, event)executeCallback(appdesigner.internal.service.AppManagementService.instance(), ...
Error while evaluating Button PrivateButtonPushedFcn.
Walter Roberson
Walter Roberson 2022 年 5 月 27 日
df = diff(str2sym(app.fun),x);
CHUNG SI HAO
CHUNG SI HAO 2022 年 5 月 27 日
there is a new problem again
Error while evaluating Button PrivateButtonPushedFcn.
Unrecognized property 'value' for class 'matlab.ui.control.EditField'.
Error in NEWTONRAPHSON/STARTButtonPushed (line 40)
app.dfdxEditField.value = char(df) ;
Error in matlab.apps.AppBase>@(source,event)executeCallback(appdesigner.internal.service.AppManagementService.instance(),app,callback,requiresEventData,event) (line 63)
newCallback = @(source, event)executeCallback(appdesigner.internal.service.AppManagementService.instance(), ...
Error while evaluating Button PrivateButtonPushedFcn.
Walter Roberson
Walter Roberson 2022 年 5 月 27 日
app.dfdxEditField.Value = char(df) ;
CHUNG SI HAO
CHUNG SI HAO 2022 年 5 月 27 日
i dont understand what u mean
Walter Roberson
Walter Roberson 2022 年 5 月 27 日
Change line 40
app.dfdxEditField.value = char(df) ;
to become
app.dfdxEditField.Value = char(df) ;
Notice value with lower case becomes Value with upper case
CHUNG SI HAO
CHUNG SI HAO 2022 年 5 月 27 日
then it become like this
Error using sym>convertChar
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 1608)
S = convertChar(x);
Error in sym (line 400)
S.s = tomupad(x);
Error in subs (line 66)
r_unique_name = evalin('caller',cmd_unique_name);
Error in NEWTONRAPHSON/STARTButtonPushed (line 46)
Function = subs(app.fun);
Error in matlab.apps.AppBase>@(source,event)executeCallback(appdesigner.internal.service.AppManagementService.instance(),app,callback,requiresEventData,event) (line 63)
newCallback = @(source, event)executeCallback(appdesigner.internal.service.AppManagementService.instance(), ...
Error while evaluating Button PrivateButtonPushedFcn.
Walter Roberson
Walter Roberson 2022 年 5 月 27 日
change
x = xold;
Function = eval(app.fun);
Derivative = eval(df);
to
Function = double(subs(str2sym(app.fun),x,xold));
Derivative = double(subs(df, x, xold)) ;
Walter Roberson
Walter Roberson 2022 年 5 月 27 日
Have you considered how much easier it would be if you had stored str2sym of the function in app.fun instead of converting the text to symbolic all the time? And have you considered how much easier it would be to use matlabFunction?
CHUNG SI HAO
CHUNG SI HAO 2022 年 5 月 27 日
how to stored str2sym in app.fun
this my app.fun
properties (Access = private)
fun
end
Walter Roberson
Walter Roberson 2022 年 5 月 27 日
At some point you have code similar to
app.fun = app.Editfield1.Value;
You would change that to
app.fun = str2sym(app.Editfield1.Value);
CHUNG SI HAO
CHUNG SI HAO 2022 年 5 月 28 日
Thank you Sir I got it

サインインしてコメントする。

回答 (0 件)

質問済み:

2022 年 5 月 27 日

コメント済み:

2022 年 5 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by