Filter löschen
Filter löschen

Symbolic or function handle to numeric

1 Ansicht (letzte 30 Tage)
Drew Mitchell
Drew Mitchell am 20 Apr. 2016
Beantwortet: Walter Roberson am 21 Apr. 2016
Is there a way to turn a symbolic expression or function handle into a numeric expression? For example, say i have:
syms x
y=x^2;
and would like to turn it into to this
y=x^2;
Where x is no longer a symbolic variable such that when I give x a value like
x=[1 2 3];
and I type
y
I get
y=[1 4 9];
I know function handles will do this but matlab coder can not take function handles, so is there a way to do this?
Thanks
Drew

Antworten (2)

Azzi Abdelmalek
Azzi Abdelmalek am 20 Apr. 2016
Bearbeitet: Azzi Abdelmalek am 20 Apr. 2016
syms x;
y=x^2;
out=subs(y,[1 2 3])
  3 Kommentare
Azzi Abdelmalek
Azzi Abdelmalek am 20 Apr. 2016
Bearbeitet: Azzi Abdelmalek am 20 Apr. 2016
have you tried inline function?
y=inline('x.^2')
Drew Mitchell
Drew Mitchell am 20 Apr. 2016
That is also not supported by coder.
I appreciate the responses though Thanks!!

Melden Sie sich an, um zu kommentieren.


Walter Roberson
Walter Roberson am 21 Apr. 2016
syms is not supported by the coder either. So anything having to do with symbolics has to be done and over with before code is generated. At the time you are running the symbolic code, you can use matlabFunction to write to a file.

Kategorien

Mehr zu Function Creation 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!

Translated by