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.

采纳的回答

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 CenterFile Exchange 中查找有关 Number Theory 的更多信息

标签

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by