Passing a vector (array) into a differentiated function

1 回表示 (過去 30 日間)
Enis Gerxhalija
Enis Gerxhalija 2021 年 12 月 9 日
回答済み: David Hill 2021 年 12 月 9 日
I'm new to Matlab, and I'm having a bit of a problem with a bit of my code, which I present below:
Essentially, I am trying to pass array values (which here is my domain x) into my functions, and the functions respective derivatives.
%I try to do this in the following way:
f = @(x) x^2 -1; %functions and its derivatives we are handling
Df1 = @(x) diff(sym(f))
Df2 = @(x) diff(sym(Df1))
x = (0:0.05:1);% our bounds, with intervals
f1 = arrayfun(f,x);
diff1 = arrayfun(Df1,x);
diff2 = arrayfun(Df2,x);
When doing this though, I encounter the following error code:
Error using arrayfun
First input must be a function handle.
Where have I gone wrong/what am I not understanding, as it seems pretty simple.

採用された回答

David Hill
David Hill 2021 年 12 月 9 日
syms x;
f = x^2 -1;
Df1 = diff((f));
Df2 = diff((Df1));
y = (0:0.05:1);
F= double(subs(f,x,y));
DF1= double(subs(Df1,x,y));
DF2= double(subs(Df2,x,y));

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumber Theory についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by