Derivative of a function with value of x
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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!
0 Kommentare
Antworten (1)
John D'Errico
am 11 Nov. 2020
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)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Conversion Between Symbolic and Numeric finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!