What's wrong with the folow expression?

f is my imput function and i have to find the first and the second derivate.
I tried to define
df=diff(f);
f2=diff(f,2);
f1=inline (f);
df1=inline(df);
df2=inline (f2);
but appears
Error using inline (line 51)
Input must be a string." Error in convergefinal (line 11)"
df1=inline(df);
What could it be?

 Réponse acceptée

Walter Roberson
Walter Roberson le 3 Déc 2013
diff(f) would invoke f with no arguments, fetch its return value, and apply the numeric diff() function to it, where the numeric diff() function is (X(2:end) - X(1:end-1)).
If you have the symbolic toolbox, you could try
syms t
df = diff(f(t),t);
f2 = diff(df,t);
f1 = inline(char(f(t)));
df1 = inline(char(df));
df2 = inline(char(f2));
Or more directly,
syms t
ft = f(t);
df = diff(ft,t);
f2 = diff(df, t);
f1 = @f;
df1 = matlabFunction(df, 'vars', t);
df2 = matlabFunction(f2, 'vars', t);
f

Plus de réponses (0)

Catégories

En savoir plus sur Function Creation dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by