フィルターのクリア

Derivative of a function with value of x

8 ビュー (過去 30 日間)
CaiX
CaiX 2020 年 11 月 10 日
回答済み: John D'Errico 2020 年 11 月 11 日
Hi, I've been trying to code for the derivative of ln(x), where x is a value to be set by the user. Here's what I've done so far..
x = input('Please enter value of x: \n');
f = log(x)
y = diff(f)
disp(y)
I'm not quite sure if im on the right track... should I use
syms x
or
diff(f,x)
I would greatly appreciate any help/explanation. Thank you and stay safe!

回答 (1 件)

John D'Errico
John D'Errico 2020 年 11 月 11 日
You want to find the derivative of a function. First, create the function in a symbolic form.
syms x
f = log(x);
So f is a variable, containing the "function" we want. First, differentiate it.
df = diff(f,x);
So df is a variable. It contains the derivative, but it is not truly a function.
Now, choose a point to evaluate the function at.
x0 = input('Please enter value of x: \n');
And substitute into df. We can use subs for that.
subs(df,x,x0)
Or, if you prefer, we can convert df into a function.
df_fun = matlabFunction(df,x);
df_fun(x0)

カテゴリ

Help Center および File ExchangeConversion Between Symbolic and Numeric についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by