Solving an Equation in Matlab
Mostrar comentarios más antiguos
I am trying to solve the following for t:
(16.68t) - ((16.68 - 0)*(1-(exp(-0.21t)))/0.21) - (8.5) = 0
4 comentarios
John D'Errico
el 15 de Oct. de 2022
Editada: John D'Errico
el 15 de Oct. de 2022
help fzero
Unless, of course, this is just your homework. In which case you would have been directed not to use fzero. But then you would need to be doing the work yourself anyway.
Sean Sarran
el 15 de Oct. de 2022
Editada: dpb
el 15 de Oct. de 2022
t = fzero(@(t)16.68*t - (16.68*(1-(exp(-0.21*t)))/0.21) - 110.85,10)
fzero will find the nearest root; change the starting value...
Sean Sarran
el 15 de Oct. de 2022
Respuestas (1)
John D'Errico
el 15 de Oct. de 2022
Editada: John D'Errico
el 15 de Oct. de 2022
Sounds like you got an answer that worked, but let me expand. You have a function:
f = @(t)16.68*t - (16.68*(1-(exp(-0.21*t)))/0.21) - 110.85;
And you need to find a zero, that is, a value of t such that f(t)==0.
First, ALWAYS PLOT EVERYTHING. Then, find something more to plot, if plotting everything was not sufficient. And when done, think about what you see. Does what you see make sense?
fplot(f)
So no solution in the interval [-5,5], the default for fplot.
fplot(f,[-20,20])
grid on
And that tells us there will be two roots. A negative one, and a positive one. One will be near -5, and the other near +10. Well, at LEAST two roots. If we looked further out, we may find more.
If you give fzero only ONE starting value, then it tries to find a root, but it won't really care which one it finds. A root is a root for god sakes! You asked for a root. ;-) For example:
[xsol,fval] = fzero(f,0)
You can see it decided to find the negative root, but that is just the one it found.
If you want to find the positive one, then use a bracket for fzero that is positive. A bracket is a pair of values for x, such that the function is positive at one end, and negative at the other.
[xsol,fval] = fzero(f,[0,1000])
This will insure that fzero always finds the positive root.
1 comentario
Sean Sarran
el 15 de Oct. de 2022
Categorías
Más información sobre Optimization en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

