Is there any way to get numerical result from symbolic function?
110 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Volkan Yangin
am 30 Okt. 2020
Beantwortet: Walter Roberson
am 30 Okt. 2020
Hi,
I have a smybolic function created by syms command and at the next steps in my code, i should get numerical output by using this function. To do this operation, i copy the symbolic function from workspace and paste my editor. This is too long method and easy to make mistake. So, i have to use symbolic function directly.
What kind of methods can i use for this operation? Do you have any example about this?
Thx!
0 Kommentare
Akzeptierte Antwort
Ameer Hamza
am 30 Okt. 2020
Bearbeitet: Ameer Hamza
am 30 Okt. 2020
If you have a symbolic function, you can directly evaluate by giving the input. For example
syms x
y(x) = x.^2 + 2*x + 3; % symbolic function
Then run the following
>> y(3)
ans =
18
>> y(100)
ans =
10203
If you want output in floating-point format, you can use double()
double(y(100))
If you have a symbolic expression, then you can use subs()
syms x
y = x.^2 + 2*x + 3; % symbolic expression
and then run
>> subs(y, x, 3)
ans =
18
>> subs(y, x, 100)
ans =
10203
0 Kommentare
Weitere Antworten (2)
KSSV
am 30 Okt. 2020
You can substitute a variable value in the syms using subs and then use double, vpasolve to convert into numerica array.
Read about subs, double.
0 Kommentare
Walter Roberson
am 30 Okt. 2020
Use matlabFunction to convert the expression into a numeric function.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Conversion Between Symbolic and Numeric finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!