Finding x that approximate y to zero

5 views (last 30 days)
I am trying to find the the value x that make y approximately zero. Here is what I did:
e= 0.001 %error bar
for x = linspace(100, 170, 1000);
y = 18.9*log(x/170) +0.0042*(x-170) + 8.314*log(0.000267/0.0001413);
end
Thanks in advance.

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 12 Jul 2015
e= 0.01 %error bar
x = linspace(100, 170, 1000);
y = 18.9*log(x/170) +0.0042*(x-170) + 8.314*log(0.000267/0.0001413);
idx=find(abs(y)<e)
  4 Comments
Azzi Abdelmalek
Azzi Abdelmalek on 12 Jul 2015
If you are looking for the nearest value to 0.
e= 0.01 %error bar
x = linspace(100, 170, 1000);
y = 18.9*log(x/170) +0.0042*(x-170) + 8.314*log(0.000267/0.0001413);
[max_val,index_val]=min(abs(y))
Abdullah Al-Alawi
Abdullah Al-Alawi on 12 Jul 2015
Thank you! Much Appreciated!

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 12 Jul 2015
Consider
x0 = fzero( @(x) 18.9*log(x/170) +0.0042*(x-170) + 8.314*log(0.000267/0.0001413), [100, 170]);
  1 Comment
Abdullah Al-Alawi
Abdullah Al-Alawi on 12 Jul 2015
Thank you Walter! That's indeed a faster way! Much Appreciated! You Rock!

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!