i can't use syms in matlab

12 visualizzazioni (ultimi 30 giorni)
adem ski
adem ski il 17 Dic 2019
Risposto: Walter Roberson il 17 Dic 2019
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

Risposte (3)

Image Analyst
Image Analyst il 17 Dic 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 Commenti
Image Analyst
Image Analyst il 17 Dic 2019
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?
adem ski
adem ski il 17 Dic 2019
I want to get the max value

Accedi per commentare.


Fangjun Jiang
Fangjun Jiang il 17 Dic 2019
run "ver symbolic". If you don't see the Symbolic Math Toolbox, then you don't have the Symbolic Math Toolbox.
  2 Commenti
adem ski
adem ski il 17 Dic 2019
yes
Symbolic Math Toolbox Version 5.2 (R2009a)
Fangjun Jiang
Fangjun Jiang il 17 Dic 2019
Then see the answer from Image Analyst. You had a typo. It should be "syms", not "sysm".

Accedi per commentare.


Walter Roberson
Walter Roberson il 17 Dic 2019
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)

Community Treasure Hunt

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

Start Hunting!

Translated by