Recursive method to get the differential not working.
1 回表示 (過去 30 日間)
古いコメントを表示
Im trying to make a recursive method to get the n:th-order differential equation.
what i have currently is 2 methods im my .m file first one being the simple 1st order differential.
function func = differential(f) % callculates the n:th-order differential
arguments
f function_handle
end
h = 10^(-5);
func = @(x)((f(x+h)-f(x))./h);
end
then im trying to use this in my recursive method
function output = differentialPower(f,n)
arguments
f function_handle
n
end
if(n==0)
output = f;
return;
else
f = differentialPower(differential(f),n-1);
output = f;
return;
end
end
to get the n:th differential
Problem i have is that my output will allways be either the original function (f)
or the first order differential of:
f = @(x)((f(x+h)-f(x))./h)
gooten from the differential method.
what i want to happen is that each time it gose deeper it will replace f(x) with ((f(x+h)-f(x))./h) and there for going deeper.
is this possible without using syms? or do i have to use the syms methods?
0 件のコメント
採用された回答
Uday Pradhan
2021 年 3 月 17 日
Hi Hampus,
You will need to use the output function handle to evaluate the nth derivative approximation:
f = @(x) x^5;
df3 = differentialPower(f,3);
%Find approximation of f'''(1)
>> df3(1)
ans =
60.174087934683492
This approximation will get highly inaccurate as you increase the order of the derivative. Instead, a neat way to calculate higher order derivatives is using the diff function.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Polynomials についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!