Substituting and evaluating function

6 visualizaciones (últimos 30 días)
Gavin Seddon
Gavin Seddon el 13 de Sept. de 2017
Comentada: Star Strider el 13 de Nov. de 2017
I have attempted to substitute the X variable into my function and evaluate it. This is the result. If it is not possible please tell me and I will find a difference method?
>> subs der(140,x);
Warning: Support of character vectors that are not valid variable names or define
a number will be removed in a future release. To create symbolic expressions,
first create symbolic variables and then use operations on them.
> In sym>convertExpression (line 1586)
In sym>convertChar (line 1491)
In sym>tomupad (line 1243)
In sym (line 199)
In subs (line 66)
>> eval der
der =
(13459*cos((313*x)/200 - 1689/2000))/25 + (42471*cos((1573*x)/1000 + 1153/500))/80 + (937443*cos((1849*x)/2500 + 441/250))/62500
GS.
  2 comentarios
Stephen23
Stephen23 el 13 de Sept. de 2017
What is der? Is it symbolic, or is it a simple function handle?
Gavin Seddon
Gavin Seddon el 13 de Sept. de 2017
Hello, der is the symbolic function that is the result of dIff fx.

Iniciar sesión para comentar.

Respuesta aceptada

Star Strider
Star Strider el 13 de Sept. de 2017
Try this (in R2012a and later):
syms x
X = sym(140);
der(x) = (13459*cos((313*x)/200 - 1689/2000))/25 + (42471*cos((1573*x)/1000 + 1153/500))/80 + (937443*cos((1849*x)/2500 + 441/250))/62500;
Desired_Symbolic_Result = der(X)
Desired_Numeric_Result = vpa(der(X))
Desired_Symbolic_Result =
(937443*cos(26327/250))/62500 + (42471*cos(111263/500))/80 + (13459*cos(436511/2000))/25
Desired_Numeric_Result =
-503.67380291547475440432522297924
Beginning in R2012a, you can create symbolic functions. You then work with them as you would any other function.
  24 comentarios
Gavin Seddon
Gavin Seddon el 13 de Nov. de 2017
Hello, this is really trivial however histogram(X) does not use my values. So how do I instruct Matlab to use my X and Y values? GS.
Star Strider
Star Strider el 13 de Nov. de 2017
The documentation provides guidance:
histogram(X,edgvct)
or if you have two arrays and you want a 2-dimensional histogram, use the histogram2 function. You may have to provide a second vector of edges for the ‘Y’ data as well. See the documentation for details.

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by