i can't use syms in matlab

clc
clear all
close all
a=1;
b=5;
sysm x real
adem=1+exp(-1);
dadem=diff(adem);
ddadem=diff(dadem);
ddadem_real=sub(ddadem,x);
[maxi,idx]=max(ddadem_real)
??? Undefined function or method 'sysm' for input arguments of type 'char'.
Error in ==> Unddddtitled at 6
sysm x real

Answers (3)

Image Analyst
Image Analyst on 17 Dec 2019
Did you mean to use/type syms instead of sysm?
Or do you have your own function called sysm? Because I'm not finding it in my help.

8 Comments

adem, did you even see my Answer? Look at the error message you copied and pasted:
"Undefined function or method 'sysm' "
There is no sysm. So now can you answer the questions I gave in my Answer? Because I think you made a typographic error.
clc
clear all
close all
a=1;
b=5;
sysm x real
adem=1+exp(-1);
dadem=diff(adem);
ddadem=diff(dadem);
ddadem_real=sub(ddadem,x);
[maxi,idx]=max(ddadem_real)
this is my program
when i run it i see the error
I know that. You gave it already. I don't have the Symbolic toolbox so I can't try it for you. Can you just TRY my suggestion:
clc
clear all
close all
a=1;
b=5;
syms x real % Instead of sysm
adem=1+exp(-1);
dadem=diff(adem);
ddadem=diff(dadem);
ddadem_real=sub(ddadem,x);
[maxi,idx]=max(ddadem_real)
and then let us know if that works or not?
??? Undefined function or method 'sub' for input arguments of type 'sym'.
Error in ==> Unddddtitled at 10
ddadem_real=sub(ddadem,x);
OK, what is sub? Why do you think that that should work? Do you have an array sub, or function sub? Who wrote this code anyway? You? If not, maybe you can get all the missing functions from the code author.
me i write this code
clc
clear all
close all
a=1;
b=5;
syms x real % Instead of sysm
adem=1+exp(-1);
dadem=diff(adem);
ddadem=diff(dadem);
ddadem_real=subs(ddadem,x);
[maxi,idx]=max(ddadem_real)
see the result
maxi =
[]
idx =
[]
>>
And when you wrote the line
ddadem_real=subs(ddadem,x);
or
ddadem_real=sub(ddadem,x);
exactly what did you think subs() or sub() would do?
I want to get the max value

Sign in to comment.

Fangjun Jiang
Fangjun Jiang on 17 Dec 2019
run "ver symbolic". If you don't see the Symbolic Math Toolbox, then you don't have the Symbolic Math Toolbox.

2 Comments

yes
Symbolic Math Toolbox Version 5.2 (R2009a)
Then see the answer from Image Analyst. You had a typo. It should be "syms", not "sysm".

Sign in to comment.

adem=1+exp(-1);
That is a numeric scalar, nothing to do with the symbolic toolbox. You declared symbolic x on the line above but you do not use x here.
dadem=diff(adem);
diff() applied to a numeric array is the numeric difference operator, like adem(2:end)-adem(1:end-1) . It is not the mathematical derivative operator when applied to a numeric array, it is the finite difference operator when applied to numeric arrays. When you apply the finite difference operator to a numeric scalar, then because there is no second value to take the difference against, the result is the empty array.
ddadem_real=subs(ddadem,x);
If we ignore for a second that ddadem is the empty numeric array, then with x being a symbolic variable, the effect of subs(ddadem,x) would be to look inside ddadem for places where symbolic x occurred, and to look in the workspace for a current definition for x, and replace the symbolic x with the current definition of x. The current definition of x is as the symbolic variable x so if subs() did find symbolic variable x inside ddadem it would replace it with the same symbolic variable. The only change would be the side effect of converting the numeric ddadem to symbolic.
I recommend against using the two-input form of subs(): it is very easy to get wrong. For example if you had
syms x
y = x^2 + 5;
x = 7;
subs(y, x)
then this does not do the obvious of looking inside y for the variable named x and replacing it with the current numeric value of x. Instead, it would be an error, because at the time of the call, x would be a numeric variable but the second parameter of subs() must be a symbolic variable (or array of symbolic variables.) To achieve that effect you would need to do something like
syms x
x_variable_name = x;
y = x^2 + 5;
x = 7;
subs(y, x_variable_name)
then x_variable_name would have saved a copy of x when it was the symbolic variable, and that saved copy would provide the symbolic variable name x to subs() to permit subs() to know to look inside the workspace for a numeric variable named x to do the substitution.
In the large majority of cases if you use a symbolic variable name and assign a numeric value to the same variable later, you will get confused about whether the variable name is representing the symbolic variable or the numeric variable -- and if you do not get confused, then you can be sure that other people reading your code will get confused. I recommend strongly against risking it. I recommend instead something like
syms x
y = x^2 + 5;
x_numeric = 7;
subs(y, x, x_numeric)

Asked:

on 17 Dec 2019

Answered:

on 17 Dec 2019

Community Treasure Hunt

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

Start Hunting!