how to calculate a derivative
518 ビュー (過去 30 日間)
古いコメントを表示
can some one guide me how to calculate a derivative and integration in matlab . can you please give a little example.
採用された回答
bym
2012 年 2 月 26 日
Symbolically
syms x real
f = 1/x
int(f,1,2) % integration
ans =
log(2)
diff(f) %differentiation
ans =
-1/x^2
[edit - amplification]
syms x a b real positive
f = 1/x
f =
1/x
int(f) % without limits
ans =
log(x)
int(f,a,b) % with limits
ans =
log(b) - log(a)
fn = matlabFunction(f) % convert symbolic to anonymous function
fn =
@(x)1./x
quadgk(fn,1,2) % integrate numerically
ans =
0.6931
log(2) % previous result from symbolic integration
ans =
0.6931
(fn(2+1e-6)-fn(2))/1e-6 %numerical derivative at fn(2)
ans =
-0.2500
subs(diff(f),2) %substitute 2 into symbolic result previously obtained
ans =
-0.2500
5 件のコメント
Jan
2012 年 2 月 27 日
Yes, Nasir, then the integral is calculated from 1 to 2. "Symbolically" mean calculations with symbols, usually characters. The result is a formula. "Numerically" means, that you calculate a numerical value, a number.
Sergio E. Obando
2024 年 6 月 15 日
Just here to suggest some recent resources, There is a nice section in the Symbolic Math Toolbox with additional examples for differentiation as well as a FEX curriculum on this topic:
その他の回答 (3 件)
Magdalena Glinska
2020 年 11 月 16 日
f = @(x) sin(x);
second_derivative_f = matlabFunction(diff(sym(f)));
0 件のコメント
Hamza saeed khan
2020 年 11 月 24 日
syms x
f = x;
diff(f,x)
why this code give me error as;
>>Error in diff (line 1)
syms x
4 件のコメント
Steven Lord
2025 年 5 月 12 日
"même chez moi le diff là ne donne pas"
Please show us the exact code you're running and all the text displayed in red in the Command Window (and if there are any warning messages displayed in orange, please show us those too) that you see when you run that code. The exact text may be useful and/or necessary to determine what's going on and how to avoid the warning and/or error.
Achimsettythanmay
2022 年 11 月 14 日
編集済み: Walter Roberson
2022 年 11 月 15 日
syms x real
f = 1/x
int(f,1,2) % integration
diff(f) %differentiation
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Special Values についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!