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!