Substituting and evaluating function

조회 수: 6 (최근 30일)
Gavin Seddon
Gavin Seddon 2017년 9월 13일
댓글: Star Strider 2017년 11월 13일
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
Stephen23
Stephen23 2017년 9월 13일
What is der? Is it symbolic, or is it a simple function handle?
Gavin Seddon
Gavin Seddon 2017년 9월 13일
Hello, der is the symbolic function that is the result of dIff fx.

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2017년 9월 13일
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
Gavin Seddon
Gavin Seddon 2017년 11월 13일
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 2017년 11월 13일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by