Antonio
Antonio

Reputation: 131

Convert inline function to sym in Matlab R2010b

I'm trying to convert an inline function to sym in matlab R2010b but it doesn't work. In matlab 2008 worked well. Here the code:

in = inline('t^2');
syms t real
sym(in);
??? Error using ==> sym.sym>tomupad at 2178
Conversion to 'sym' from 'inline' is not possible.

Error in ==> sym.sym>sym.sym at 111
                S.s = tomupad(x,'');

Upvotes: 0

Views: 2464

Answers (2)

Nasser
Nasser

Reputation: 13141

Using http://www.mathworks.com/matlabcentral/fileexchange/33025

in = inline('t^2');
f0 = inline2sym(in);

EDU>> f0

t^2

EDU>> syms t
EDU>> diff(f0,t)

ans =

2*t

Upvotes: 0

nicktruesdale
nicktruesdale

Reputation: 815

Instead of inline, you can use an anonymous function via a function handle:

f = @(t) t.^2;
syms t
F = sym(f);

which should give you the same inline functionality/portability.

Upvotes: 1

Related Questions