How can I use fzero on these two functions?

8 views (last 30 days)
I can't seem to get fzero to work on these two functions. I tried rearanging them to bring it to one side but it would not work. Please help me with this.
This is the code I have been trying to use for the second problem
f=@(x) (log(4*x-3))/-0.1
fzero(f,[0 4])
It then gives me this error
Error using fzero
Function values at interval endpoints must be finite and real.
Error in A3_SECTION_07_501178997_501160077 (line 6)
fzero(f,[0 4])

Accepted Answer

John D'Errico
John D'Errico on 8 Oct 2022
Edited: John D'Errico on 8 Oct 2022
Why in the name of god and little green apples do you want to transform the function, by taking the log? Just move the exponential to the right hand side, so fzero will be looking for a zero result.
First, verify a solution exists.
F2 = @(x) -exp(-0.1*x) + 4*x - 3;
fplot(F2,[0,4])
grid on
Clearly, one does, and it is near x==1.
fzero(F2,[0,4])
ans = 0.9767
  2 Comments
Hadi
Hadi on 8 Oct 2022
I put it into desmos and it was giving me a completly differnent graph so I thought it was wrong. It now makes sense though so thank you. (I will also be using your phrase "why in the name of god and little green apples" so much)
John D'Errico
John D'Errico on 8 Oct 2022
Just a phrase I always liked. :-) It does seem to fit on Answers often enough.

Sign in to comment.

More Answers (2)

Torsten
Torsten on 8 Oct 2022
Use the original equation. Why do you take log on both sides - it only implies problems for x <= 3/4.
f = @(x)4*x-3-exp(-0.1*x);
x0 = fzero(f,[0 4])
x0 = 0.9767
f(x0)
ans = -1.1102e-16

Matt J
Matt J on 8 Oct 2022
Edited: Matt J on 8 Oct 2022
If you are going to transform the function, you must restrict the search to the domain where the transform is valid,
f=@(x) log(4*x-3)+0.1*x;
fzero(f,[3/4+eps,4])
ans = 0.9767

Categories

Find more on Optimization in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!