Passing a vector (array) into a differentiated function
1 回表示 (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
採用された回答
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Number Theory についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!