# How can I a function on the interval

6 views (last 30 days)
Wenchen Liu on 1 Nov 2022
Answered: Star Strider on 1 Nov 2022
I got a equation: x+ln x = 0, and I want to plot it on the interval [0.1, 1]
I have tried this code:
f = @(x)x+log(x)
f = function_handle with value:
@(x)x+log(x)
fplot(f,[0.1 1]) But it only shows: f =
function_handle with value:
@(x)x+log(x)
Is anything wrong with my code? Thank you!
Torsten on 1 Nov 2022
You didn't set a
;
at the end of the line
f = @(x)x+log(x)
So f is displayed.
But the plot follows - so everything is fine.

Star Strider on 1 Nov 2022
If you want the x and y values, you need to ask for them —
f = @(x)x+log(x)
f = function_handle with value:
@(x)x+log(x)
hfp = fplot(f,[0.1 1]); x = hfp.XData
x = 1×47
0.1000 0.1094 0.1188 0.1298 0.1409 0.1623 0.1818 0.2019 0.2227 0.2453 0.2636 0.2864 0.3045 0.3243 0.3455 0.3651 0.3864 0.4092 0.4273 0.4492 0.4682 0.4897 0.5091 0.5294 0.5500 0.5705 0.5909 0.6122 0.6318 0.6539
y = hfp.YData
y = 1×47
-2.2026 -2.1035 -2.0118 -1.9116 -1.8187 -1.6558 -1.5229 -1.3982 -1.2791 -1.1600 -1.0695 -0.9638 -0.8844 -0.8019 -0.7174 -0.6424 -0.5646 -0.4844 -0.4231 -0.3511 -0.2907 -0.2242 -0.1660 -0.1067 -0.0478 0.0091 0.0648 0.1214 0.1727 0.2291
.